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?
Add comment