New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Custom Sensor and Graph Object

Votes:

0

Your Vote:

Up

Down

How to create a custom sensor (and graph) that monitors a continuously updated log file?

api custom-exe custom-script-exe custom-sensor graphs map-objects python script

Created on Aug 30, 2011 3:15:58 PM by  Daniel (61) 2 1

Last change on Mar 16, 2015 5:10:09 PM by  Martina Wittmann [Paessler Support]



1 Reply

Accepted Answer

Votes:

1

Your Vote:

Up

Down

Using PRTG’s custom sensor API, and a little bit of python, I was able to create a beautiful custom sensor and map object. The python script (which had to be turned into an exe in order for prtg to run it) reads some continuously updated log output from one of our applications, and parses it into PRTG-readable xml. Then all I had to do was set the channel thresholds and ta-da! I thought I’d pass on the python script in case anyone wanted to use / improve it.

First an example: Here's how the log looks on it's own:

08/01/2011, 11:39:04.2,  Data Engine 1 OK
08/01/2011, 11:39:04.3,  Client Status OK
08/01/2011, 11:39:04.4,  Document Generation OK
08/01/2011, 11:39:04.5,  Importer Engine OK
08/01/2011, 11:39:04.5,  Data Engine 2 OK
08/01/2011, 11:39:08.0,  Data Engine 3 Error

And here's the python script. It grabs lines, and based on whether the line contains "OK" or "Error" generates XML with appropriate values. (0 or 1 respectively)

import sys
def main():
    stat = ''
    logfile = open(***location of log file***)
    log = logfile.readlines()
    log = log[-6:] # Logfile is continuously updated by another process, so only last 6 entries of log are read
    logfile.close()
    # Start output 'page' --> PRTG readable XML
    page = '<prtg>' + '\n'
    tab = '\t'
    # Parse log into 'page'
    for line in log:
        line = line.split(',')
        if 'OK' in line[-1]:
            stat = '0'
            stat_index = line[-1].index('OK')
        else:
            stat_index = line[-1].index('Error')
            stat = '1'
        component = line[-1][2:stat_index -1]
        page += '\t<result>\n\t\t<channel>' + component + \
             '</channel>'+'\n\t\t<Value>' + stat + '</Value>\n\t</result>\n'
    page += '</prtg>'
    return page

if __name__ == '__main__':
    sys.stdout.write(main())

Here's the output generated from the example above.

<prtg>
    <result>
        <channel>Data Engine 1</channel>
            <Value>0</Value>
    </result>
    <result>
        <channel>Client Status</channel>
            <Value>0</Value>
    </result>
    <result>
        <channel>Document Generation</channel>
            <Value>0</Value>
    </result>
    <result>
        <channel>Importer Engine</channel>
            <Value>0</Value>
    </result>
    <result>
        <channel>Data Engine 2</channel>
            <Value>0</Value>
    </result>
    <result>
        <channel>Data Engine 3</channel>
            <Value>1</Value>
    </result>
</prtg>

After that, just set the sensor to raise an error if the value is 1, and you're all set.

Created on Aug 30, 2011 3:53:36 PM by  Daniel (61) 2 1

Last change on Aug 30, 2011 4:09:25 PM by  Torsten Lindner [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.