Hi, There.
I am trying to get some JSON output and check the status of the services we have.
However, this API requires an authentication method which we are using API Keys.
I've tried check_json script, but it doesn't show an option to provide the keyid:secret.
Is any way to accomplish that?
Thanks.
How to get JSON output using API Key.
Re: How to get JSON output using API Key.
If you're using check_json.php which comes with the XI install then you can use the -h option to add a header to the request:
the above will add a http header called keyid with a value of secret to the request.
Code: Select all
./check_json.php -u 'http://1.2.3.4' -k '.key' -h 'keyid:secret' -w 1 -c 2As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Re: How to get JSON output using API Key.
Hi cdienger,
Thanks for your reply.
I got to run the command using the syntax below:
php /usr/local/nagios/libexec/check_json.php -u 'https://<KEYID>:<SECRET>@<URL>' -k "status" -s 'normal' -r 0 -n 2
However, it brings me the output below:
PHP Notice: Array to string conversion in /usr/local/nagios/libexec/check_json.php on line 113
CRITICAL - Value 'Array' did not match 'normal'
The value I am trying to get is:
[
{
"status": "normal", <<<<<<<<<<<<<<<<<<<<<<<<<<
"type": "string",
"fqdn": "string",
"available_seconds": 0,
"notifications": [
{
"status": "normal",
"token": "string",
"message": "string"
}
],
Maybe, I am mentioning the wrong json key format.
Thanks for your reply.
I got to run the command using the syntax below:
php /usr/local/nagios/libexec/check_json.php -u 'https://<KEYID>:<SECRET>@<URL>' -k "status" -s 'normal' -r 0 -n 2
However, it brings me the output below:
PHP Notice: Array to string conversion in /usr/local/nagios/libexec/check_json.php on line 113
CRITICAL - Value 'Array' did not match 'normal'
The value I am trying to get is:
[
{
"status": "normal", <<<<<<<<<<<<<<<<<<<<<<<<<<
"type": "string",
"fqdn": "string",
"available_seconds": 0,
"notifications": [
{
"status": "normal",
"token": "string",
"message": "string"
}
],
Maybe, I am mentioning the wrong json key format.
Re: How to get JSON output using API Key.
I ran the command using the syntax and it doesn't work. So, I used the syntax below:
php /usr/local/nagios/libexec/check_json.php -u 'https://<$KEYID>:<$SECRET>@<$URL>:<$PORT>/api/v2/health' -k 'status' -s 'normal' -r 0 -n 2
PHP Notice: Array to string conversion in /usr/local/nagios/libexec/check_json.php on line 113
CRITICAL - Value 'Array' did not match 'normal'
I am trying to retrieve this information:
[
{
"status": "normal", <<<<<<<<<<<<<<<<<<<<
"type": "string",
"fqdn": "string",
"available_seconds": 0,
"notifications": [
{
"status": "normal",
"token": "string",
"message": "string"
}
],
Is anything wrong with my code?
php /usr/local/nagios/libexec/check_json.php -u 'https://<$KEYID>:<$SECRET>@<$URL>:<$PORT>/api/v2/health' -k 'status' -s 'normal' -r 0 -n 2
PHP Notice: Array to string conversion in /usr/local/nagios/libexec/check_json.php on line 113
CRITICAL - Value 'Array' did not match 'normal'
I am trying to retrieve this information:
[
{
"status": "normal", <<<<<<<<<<<<<<<<<<<<
"type": "string",
"fqdn": "string",
"available_seconds": 0,
"notifications": [
{
"status": "normal",
"token": "string",
"message": "string"
}
],
Is anything wrong with my code?
Re: How to get JSON output using API Key.
I'll lab this up and see what I can find but it's the end of our day today, if you don't hear from me by midday tomorrow please reply to the thread so that it pops up on my dashboard.
Re: How to get JSON output using API Key.
Hi, Tks for the feedback.
After tracing the script and check the Array output, I got the way it is evaluated:
# php /usr/local/nagios/libexec/check_json.php -u '<URL>/api/v2/health' -k 0.nodes.0.services.status -s normal -r 0 -n 2
OK - Value 'normal' matched 'normal'
After tracing the script and check the Array output, I got the way it is evaluated:
# php /usr/local/nagios/libexec/check_json.php -u '<URL>/api/v2/health' -k 0.nodes.0.services.status -s normal -r 0 -n 2
OK - Value 'normal' matched 'normal'
Re: How to get JSON output using API Key.
Thank you for posting your resolution! Let us know when we're okay to lock this up and mark it as resolved.
Thank you!
Thank you!