Page 1 of 1

Searching for 'Free variables'

Posted: Thu Feb 05, 2015 11:07 am
by WillemDH
Hello,

Is there some way to search in Nagios XI for the values of the free variables definitions? For example if I set a free variable serial number, is there someway to search In Nagios XI with that serial number?

Grtz

Re: Searching for 'Free variables'

Posted: Thu Feb 05, 2015 11:12 am
by abrist
What is the use case?
You could try to search for those using a backend (xml or json). That would get you the hostname that you could then use to navigate to the desired host.

Re: Searching for 'Free variables'

Posted: Thu Feb 05, 2015 12:20 pm
by WillemDH
Hmm the use case would be to store some extra info in Nagios XI. It was just an idea, but it depends of how easy it would be to search or see that extra info. I could make a quick action linking to a pretty-json url page, like this http://warfares.github.io/pretty-json/

So if you know what host it's relatively easy to get the data, but I'm not sure how I could search for the (example) serial number with json (or xml) without knowing from which host the serial is.. Or I would have to query all hosts seperately and then look at the values.. what doesn't seem really performant.

EDIT: Some really vague idea, would it be possible to somehow extract all the object data with some job / script to json format, let's say once a day and search in this info with NLS?

Re: Searching for 'Free variables'

Posted: Thu Feb 05, 2015 1:47 pm
by abrist
Well, you can query the core json api for a json encoded full list of objects (including custom variables):

Code: Select all

http://<ip>/nagios/cgi-bin/objectjson.cgi?query=hostlist&details=true
Does this help?

Re: Searching for 'Free variables'

Posted: Thu Feb 05, 2015 1:59 pm
by WillemDH
This helps indeed! And it's superfast too. :o Really thanks Andy. I've used your JSON query generator a lot lately. Finding data in Nagios XI has been made super easy with this tool. If only it was as easy to write data back to Nagios XI. It's possible of course by editing the config files and running the import script, but rather cumbersome imho. Or does there happen to be a magic tool that converts Nagios config files to json and back? :D

Re: Searching for 'Free variables'

Posted: Thu Feb 05, 2015 5:57 pm
by abrist
Nope, not yet. Maybe someday? Or maybe never?
WillemDH wrote:It's possible of course by editing the config files and running the import script, but rather cumbersome imho
This really is the only option if you need to change non-runtime state options. For runtime-state stuff (enable/disable notifications/perfdata/checks/etc) you can just submit to the command pipe or the cmd.cgi.

The limitation here is NagiosQL (the ccm) as any changes to the configs need to be inserted/updated in the nagiosql database. Due to the highly relational nature of this db, the import procedure is the only safe way to update them. Direct queries can be *very* dangerous unless you fully understand the nagiosql relational structure.

Re: Searching for 'Free variables'

Posted: Fri Feb 06, 2015 2:19 am
by WillemDH
Ok, thanks for confirming. You can close the thread Andy.