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

Can you create channels in Python using a loop() ?

Votes:

0

Hi there, having a small issue with my python script. getting error of: 'XML: The returned XML does not match the expected schema. (code: PE233) -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)' The Script file is placed in the path: 'C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\python'

My code is this:

#######################

import sys
import requests
import json

from paepy.ChannelDefinition import CustomSensorResult
   #Functions 1

def Url_post(url_post,user_password):
    request = requests.post(url_post, auth=(user_password),verify=False)
    statusP = request.status_code
    return (statusP,request.headers['session'])

    #Functions 2
def Url_get_Data(url_get, code):

    res = requests.get(URL_get, headers={"session":code}, verify=False)

    statusG = res.status_code

    return(statusG, res.json())

###########main#######################  

if __name__ == "__main__":
    
    #main:

    status_post, send_ack = Url_post(URL_post, auth)

    status_get, result = Url_get_Data(URL_get, send_ack)

    data = json.loads(result)

    #create sensor result

    result = CustomSensorResult("this sensor is added to " + data['host'])
   
    for i in result:
    
    NameCH1, Value_Ch1= i[Name'], i['Number']
           
    	    
            result.add_channel(channel_name =[i] NameCH1, unit="s", value =[i] Value_Ch1)
   
print(result.get_json_result())

###########################

What I'm trying to do, is to take data from a server and use each returning result to create a channel. This is by passing its name and value into this line of code: result.add_channel(channel_name = [i]NameCH1, unit="s", value = [i]Value_Ch1).

Is it possible to place this in a loop and call a function to create channels. Reason is so that I can dynamically keep it up to date if a new channel is needed to be created without manually adding one or changing?

prtg prtg-desktop python-script-advanced-sensor

Created on Aug 7, 2019 9:06:09 AM

Last change on Aug 7, 2019 11:19:54 AM by  Stephan Linke [Paessler Support]



1 Reply

Votes:

0

Note that you can't remove or rename existing channels with that one. Channels with different names will simply be created anew within the Sensor :/

Created on Aug 8, 2019 9:43:11 AM by  Stephan Linke [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.