Page 1 of 1

Options to automate plugin addition and service

Posted: Sat Nov 30, 2019 12:05 pm
by dfmco
I have a plugin that I need to deploy across all monitoring environments. I would like to automate the following:

Add the check_snmp_cisco_bgp.pl plugin to nagios. Since the API does not have a way to add plugins, would it be as simple as uploading the check_snmp_cisco_bgp.pl file to /usr/local/nagios/libexec/ or is some additional configuration required to register that plugin? If so, can the registration be handled automatically as well with running a command or modifying a file?

I believe the API will allow me to build a new command using that plugin so I think that part is OK.

Finally, I would need to create a new service check using that new command/plugin for existing devices. Today we have to copy one of the existing services and modify it with the new command. While I know that you can use the API for a service, how would I be able to match the existing hostname for that service to add an additional check in automation? Is there a way to do a lookup of the hostname configured via Ansible so that the new service gets added to the correct host? Here is an example.

Config Name BM-QUARRY-H1A-ASE has 9 services being checked. I want to add an addition BGP check to that Config Name. I can send API calls via Ansible to create the service and I can have Ansible pull information from the device as well. How can I get Ansible to pull the Config Name (and loop through all Config Names) to add this new BGP check to all devices?

Thanks!

Re: Options to automate plugin addition and service

Posted: Mon Dec 02, 2019 2:12 pm
by ssax
For the plugin, you only need to put the file here:

Code: Select all

/usr/local/nagios/libexec
Then set the perms:

Code: Select all

chown apache.nagios /usr/local/nagios/libexec/plugin.ext
chmod og+x /usr/local/nagios/libexec/plugin.ext
Then add the command:

Code: Select all

https://YOURXISERVER/nagiosxi/help/api-config-reference.php#add-command
You would likely need to call the service endpoint and loop through the config_name that is returned (or build it from a process and query the config names):

Code: Select all

https://YOURXISERVER/nagiosxi/help/api-config-reference.php#get-service
[
{
"config_name": "localhost",
"host_name": [
"localhost"
],
"service_description": "Current Load",
"use": [
"local-service"
],
"check_command": "check_local_load!5.0,4.0,3.0!10.0,6.0,4.0!!!!!!",
"notes": "Testing 123",
"register": "1"
}
]

There is no inherent functionality for this at this time though.