NagiosEnterprises / ncpa

Nagios Cross-Platform Agent
Other
181 stars 94 forks source link

Unable to parse json output #87

Closed ludmilmm closed 9 years ago

ludmilmm commented 10 years ago

I am using NCPA 1.7.2 installed on Windows 7 64-bit. I can view the status of a service in the API, for example:

https://192.168.x.x:5693/api/services?service=Dhcp

{
  "value": {
    "returncode": 0, 
    "stdout": "OK: Service Dhcp is running"
  }
}

but I am not able to use the same syntax from the CLI:

/usr/local/nagios/libexec/check_ncpa.py -H 192.168.x.x -t 'token' -P 5693 -M 'services?service=Dhcp' -v or /usr/local/nagios/libexec/check_ncpa.py -H 192.168.x.x -t 'token' -P 5693 -M 'services\?service=Dhcp' -v

give me the following error:

Unable to parse json output
And error was encountered:
local variable 'rjson' referenced before assignment

However, if I use the old (deprecated) way of checking, I can get the correct output:

usr/local/nagios/libexec/check_ncpa.py -H 192.168.x.x -t 'token' -P 5693 -M 'service/Dhcp/running'
OK: Service Dhcp is running
varnar commented 10 years ago

For the current version it is correct behavior. This is what you can do for easy switching before Developers are fixing it. Prepare command "command_service_ncpa", which will equal

$USER1$/check_ncpa.py -H $HOSTADDRESS$ -P 5693 -t token -M 'service/$ARG1$/running'

So, now you can use it in service check and provide in ARG1 the service name that you wan to check.

If in future you want to change the way how to check service - you need to change only command and remember that service name is in ARG1.

krobertson71 commented 10 years ago

-M 'service/servicname/running' already works with current check_ncpa.

If i understand what you are saying is that the current check_ncpa is not capabile of querying the api using the same syntax used locally on the agent web interface?

varnar commented 10 years ago

Yes, it already works with current.

But the way that I have explained you is the way to avoid any changes, or to quick change, if developers make decision to change the behavior of agent or check_ncpa.py plugin.

krobertson71 commented 10 years ago

Sorry I should have said I understood what you were saying. This is more for end-users in operations who have a specific need to see the status of several services at once on a particular host. This would involve having a seperate check for each one.

But your information does prove usefull in other areas :).

varnar commented 10 years ago

If your checks is under windows OS based server - I can share with you my VBS script which does checks against all services that are in "Automatic" start mode.

krobertson71 commented 10 years ago

Yes please share. Assuming this would be a NCPA plugin?

varnar commented 10 years ago

does not matter with which agent you are using it. You can use it with NSClient++ or NCPA or what ever is exist :)

https://drive.google.com/folderview?id=0B1xMI2jsW6Y6bTVsN0tEbGtkbEE&usp=sharing

scot0357 commented 10 years ago

Ludmil,

I updated the check_ncpa.py plugins to now have a -q options, that should accept the query args you were attempting to use before. So all the arguments would just be the args like

check_ncpa.py args args -q 'service=Bingo,service=Bongo'```

that it will pass those as query args to the URL.
ludmilmm commented 10 years ago

Thanks, Nick! Time for testing... :)