Hi all,
We have nagios plugins that throw JSON output, which we then parse in another command (which makes alerts).
The problem is JSON output can have characters such as [$,&,\,etc] because of html data, and nagios acts strange if
these are encountered. Most of the times nagios will strip characters and the JSON then becomes invalid,
and sometimes nagios will fail to run the notification command at all.
We are already encoding [',",<,>].
What is the best way to properly get the service output on the notification command?
One more thing is, the ';' character is replaced by ':', why?
And also is this the way to do it, or is there a better way to send bigger outputs like we are throwing?
Thanks in advance.
Problem with JSON server output in nagios plugin.
Re: Problem with JSON server output in nagios plugin.
Since this would all be displayed in the browser, you could try HTML-escaping the characters:
http://www.ascii.cl/htmlcodes.htm
This should make them display properly in a web page, but anything further down the road that would need to handle the output may not understand HTML entities.
http://www.ascii.cl/htmlcodes.htm
This should make them display properly in a web page, but anything further down the road that would need to handle the output may not understand HTML entities.
Former Nagios employee
- Box293
- Too Basu
- Posts: 5126
- Joined: Sun Feb 07, 2010 10:55 pm
- Location: Deniliquin, Australia
- Contact:
Re: Problem with JSON server output in nagios plugin.
Can you be a little more specific?xitkov wrote:We have nagios plugins that throw JSON output, which we then parse in another command (which makes alerts).
Is the plugin run on the Nagios server and receiving back JSON data?
When does the other command get run and how?
FYI I have a very similar situation and here is how I overcome the problem:
- On the Nagios server I am inside a PHP script
The PHP script executes a check_by_ssh request to a remote server
The remote server runs the command (perl script)
The perl script then does it's job by collecting some data and storing it in a JSON string
I then encode the JSON string so it ends up just as one long string of garbled characters
The perl script prints the encoded string and exits
Nagios server receives the encoded string
The PHP script receives the encoded string as multiple lines
I concatenate all the lines together to get one long encoded string
I then decode that string back to a JSON
I then use the PHP json_decode() function to turn that into an array
Now I can access the data as an array
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: Problem with JSON server output in nagios plugin.
I have tried escaping HTML characters, but Nagios replaces ';' with ':', so again I have to encode ';' also, or use a non-standard encoding/decoding scheme.tmcdonald wrote:Since this would all be displayed in the browser, you could try HTML-escaping the characters:
http://www.ascii.cl/htmlcodes.htm
This should make them display properly in a web page, but anything further down the road that would need to handle the output may not understand HTML entities.
Is encoding the characters the only way to achive this?
Re: Problem with JSON server output in nagios plugin.
Like the way you are using Nagios, we are also using php scripts as plugins and use encoding/decoding too.Box293 wrote:Can you be a little more specific?
Yes, the plugin runs on Nagios server and it returns JSON data in case of alert.Box293 wrote:Is the plugin run on the Nagios server and receiving back JSON data?
Nagios then runs a "service notification command" and there it passes the data on the command line (using $SERVER_OUTPUT$ macro).
Like I said the other command runs when the first command returns some problem for the service.Box293 wrote:When does the other command get run and how?
Looks like encoding the output is the only way this can be achieved natively, and also there's that 4 KiB limit, so we are moving ahead with our custom solution which won't require encoding/decoding and won't have such size limit too.
Thanks for your replies
Re: Problem with JSON server output in nagios plugin.
Sorry we couldn't be of more assistance. I am definitely curious about the semi-colon issue however. I might ask a dev about that.
Former Nagios employee