I would like to use the API to add hosts to Nagios XI.
Part of adding hosts this way would involve using Free Variables, so I can communicate that the host was added dynamically. Also, the Free Variables would provide important information used by service tests.
So far, I have been unable to add a host via the API and have Free Variables show up.
Is the API limited to adding only standard items? Is there a way for the API to add Free Variables?
Thanks
Steve B
Nagios API and Free Variables
-
SteveBeauchemin
- Posts: 524
- Joined: Mon Oct 14, 2013 7:19 pm
Nagios API and Free Variables
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
Re: Nagios API and Free Variables
I'm unable to get it to add the free variables either, I'll see if I can get you a workaround.
I don't think it currently supports it, here is a feature request for it:
I don't think it currently supports it, here is a feature request for it:
Code: Select all
NEW TASK ID 8675 created - Nagios XI Feature Request: API - Add the ability to add free variablesRe: Nagios API and Free Variables
Do you only need it on the host level?
*** This was written for Nagios XI 5.2.8
*** Note: This will get reverted if you upgrade and will need to be reimplemented.
*** Make sure that you have known-good backups/vm snapshots before making any modifications
If so, edit this file:
Around line 539 change this code:
To this:
Then you can just prepend any free variables with underscores (as is required per the documentation) like so:
*** This was written for Nagios XI 5.2.8
*** Note: This will get reverted if you upgrade and will need to be reimplemented.
*** Make sure that you have known-good backups/vm snapshots before making any modifications
If so, edit this file:
Code: Select all
/usr/local/nagiosxi/html/api/includes/utils-api.inc.phpCode: Select all
foreach ($others as $o) {
if (array_key_exists($o, $args)) {
if ($o == 'check_command') { $args[$o] = stripslashes($args[$o]); }
$obj[$o] = $args[$o];
}
}Code: Select all
foreach ($others as $o) {
if (array_key_exists($o, $args)) {
if ($o == 'check_command') { $args[$o] = stripslashes($args[$o]); }
$obj[$o] = $args[$o];
}
}
// Add any free variables that we find (they must start with an underscore)
foreach ($args as $key => $value) {
if (substr($key, 0, 1) === '_') {
$obj[$key] = $value;
}
}Code: Select all
&_variable1name=variable1value&_variable2name=variable2value-
SteveBeauchemin
- Posts: 524
- Joined: Mon Oct 14, 2013 7:19 pm
Re: Nagios API and Free Variables
I do only need it at the host level, and it won't be the first time I've had to change the php code to get stuff doing what I need.
Awesome feedback!
I will let you know some time on Thursday if that worked for me.
Thanks
Steve B
Awesome feedback!
I will let you know some time on Thursday if that worked for me.
Thanks
Steve B
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
Re: Nagios API and Free Variables
Sure. We will keep the thread open.I will let you know some time on Thursday if that worked for me.
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
SteveBeauchemin
- Posts: 524
- Joined: Mon Oct 14, 2013 7:19 pm
Re: Nagios API and Free Variables
Did I say Thursday? I meant Friday.
I added the couple lines in today and it's awesome. The API just got better, smarter...
Someone should make that a permanent change.
Thanks
Steve B
I added the couple lines in today and it's awesome. The API just got better, smarter...
Someone should make that a permanent change.
Thanks
Steve B
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
Re: Nagios API and Free Variables
Awesome, I'm glad you like it! Is it okay if we mark this as resolved and lock the thread?
-
SteveBeauchemin
- Posts: 524
- Joined: Mon Oct 14, 2013 7:19 pm
Re: Nagios API and Free Variables
yes to the lock question.
XI 5.7.3 / Core 4.4.6 / NagVis 1.9.8 / LiveStatus 1.5.0p11 / RRDCached 1.7.0 / Redis 3.2.8 /
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1
SNMPTT / Gearman 0.33-7 / Mod_Gearman 3.0.7 / NLS 2.0.8 / NNA 2.3.1 /
NSClient 0.5.0 / NRPE Solaris 3.2.1 Linux 3.2.1 HPUX 3.2.1