What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags

View all Tags

Custom Sensor and Graph Object



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

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

1 Reply

Accepted Answer



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
    # 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')
            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__':

Here's the output generated from the example above.

        <channel>Data Engine 1</channel>
        <channel>Client Status</channel>
        <channel>Document Generation</channel>
        <channel>Importer Engine</channel>
        <channel>Data Engine 2</channel>
        <channel>Data Engine 3</channel>

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

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

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.