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 Lookup that goes into error when false statement is caught instead of true

Votes:

0

Hi all,

I have tried all possibilities to create a lookup for an http xml/rest value sensor that succesfully returns the value of the json page

"chatEnabled": true 

Now, I am trying to create a lookup that will set the sensor in error state when the statement true becomes false, I've seen that the sensor sticks with value 0 because it can return the value but it cannot change the state of the sensor based on "text" limits...

My try at the lookup:

<?xml version="1.0" encoding="UTF-8"?>
<ValueLookup desiredValue="True" id="statement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd">
    <Lookups>
        <SingleInt state="Ok" value="True">True</SingleInt>
        <SingleInt state="Error" value="False">False</SingleInt>
    </Lookups>
</ValueLookup>

Thanks!

http-xml-rest-value-sensor json prtg

Created on Jun 30, 2022 10:02:48 PM

Last change on Jul 4, 2022 6:47:49 AM by  Luciano Lingnau [Paessler]



1 Reply

Votes:

1

Hello Mihai,
thank you for your inquiry!

The reason why you're getting the zero right now is because PRTG is unable to parse the string and then returns 0 for that channel. The issue here is that you have to work with numerical values in lookups, and not text*. For example here's the prtg.standardlookups.yesno.stateyesok:

<?xml version="1.0" encoding="UTF-8"?>
<ValueLookup id="prtg.standardlookups.yesno.stateyesok" desiredValue="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd">
	<Lookups>
		<SingleInt state="Ok" value="1">Yes</SingleInt>
		<SingleInt state="Error" value="2">No</SingleInt>
	</Lookups>
</ValueLookup>

The value="1" must always contain an interger. Strings or float values are not supported here. This does however mean that your script must take this into account and parse whatever text result you get to a numerical value first. So basically the sensor turns the string into a number and the lookup converts the number back to a string in PRTG's interface. This is because PRTG's Database (and channels) don't support strings, only numerical values.

Real-world example

Here's an example of a Powershell script to monitor the Replication Status of a DHCP Scope on Windows Server (partial-excerpt from the script):

[...]
		}'Replication'{
			
			#Parse the results for Replication
			
			switch ($remoteResult.state){
				'NoState'                  { $state = 0 }
				'Normal'                   { $state = 1 }
				'Init'                     { $state = 2  }
				'CommunicationInterrupted' { $state = 3  }
				'PartnerDown'              { $state = 4  }
				'PotentialConflict'        { $state = 5  }
				'Startup'                  { $state = 6  }
				'ResolutionInterrupted'    { $state = 7  }
				'ConflictDone'             { $state = 8  }
				'Recover'                  { $state = 9  }
				'RecoverWait'              { $state = 10  }
				'RecoverDone'              { $state = 11  }
				default                    { $state = -1  }
			}
			
			$results += @{
				Channel = 'State'
				Value = $state
				ValueLookup = 'prtg.customlookups.dhcp.failoverreplication'
			}
[...]

And here's the corresponding lookup:

<?xml version="1.0" encoding="UTF-8"?>
<ValueLookup id="prtg.customlookups.dhcp.failoverreplication" desiredValue="1" undefinedState="Error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd">
	<Lookups>
		<SingleInt state="Error" value="-1">Unknown Status</SingleInt>
		<SingleInt state="Error" value="0">No State</SingleInt>
		<SingleInt state="Ok" value="1">Normal</SingleInt>
		<SingleInt state="Warning" value="2">Init</SingleInt>
		<SingleInt state="Error" value="3">Communication Interrupted</SingleInt>
		<SingleInt state="Error" value="4">Partner Down</SingleInt>
		<SingleInt state="Warning" value="5">Potential Conflict</SingleInt>
		<SingleInt state="Warning" value="6">Startup</SingleInt>
		<SingleInt state="Error" value="7">Resolution Interrupted</SingleInt>
		<SingleInt state="Ok" value="8">Conflict Done</SingleInt>
		<SingleInt state="Warning" value="9">Recover</SingleInt>
		<SingleInt state="Warning" value="10">Waiting for Recovery</SingleInt>
		<SingleInt state="Ok" value="11">Recovery Done</SingleInt>
	</Lookups>
</ValueLookup>

Side note: On the first line of my answer I wrote "you have to work with numerical values in lookups, and not text*" - The asterisk there is not an accident. When you work with the SNMP Custom String Lookup sensor, you can actually work with strings in lookup-files, but that's an exception and not the norm:

Best Regards,
Luciano Lingnau [Paessler]

Created on Jul 4, 2022 7:01:27 AM by  Luciano Lingnau [Paessler]

Last change on Jul 4, 2022 7:03:36 AM by  Luciano Lingnau [Paessler]




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.