Leverage API to add/remove/update devices

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dfmco
Posts: 257
Joined: Wed Dec 04, 2013 11:05 am

Leverage API to add/remove/update devices

Post by dfmco »

We are using the router/switch wizard to load in devices for SNMP V3 monitoring. I am fairly sure that the Wizard also sets up mrtg as well. If I use the API to set up the router/switch, how can I also set up mrtg to get the graphs? Can I use PUT instead of POST to create the initial instance? I would prefer to do this as we are using Ansible and it would be easier and cleaner to only have to consider a single API call in the playbook.
jomann
Development Lead
Posts: 611
Joined: Mon Apr 22, 2013 10:06 am
Location: Nagios Enterprises

Re: Leverage API to add/remove/update devices

Post by jomann »

You are correct that running the switch wizard does create mrtg files as well as the host/service definitions. In order to add these special checks without running the wizard, you would have to manually make those mrtg files and then add the hosts/services afterwards. Currently there is no way to run the wizard or set up mrtg-specific checks from the API.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
dfmco
Posts: 257
Joined: Wed Dec 04, 2013 11:05 am

Re: Leverage API to add/remove/update devices

Post by dfmco »

So I know we can create the hosts/services from the API but is there any documentation or information you can send on how exactly to make the mrtg files? That may be easy for us by using the template engine but I have to be able to understand all of the steps involved to be sure.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Leverage API to add/remove/update devices

Post by lmiltchev »

As @jomann stated clearly:
Currently there is no way to run the wizard or set up mrtg-specific checks from the API.
Be sure to check out our Knowledgebase for helpful articles and solutions!
dfmco
Posts: 257
Joined: Wed Dec 04, 2013 11:05 am

Re: Leverage API to add/remove/update devices

Post by dfmco »

I think you misunderstood my comments....

The API will not work for setting up MRTG and I can't run the wizard from the CLI so both of those options are off the table.

What I am trying to acquire is documentation on how MRTG would be set up MANUALLY if I was not using the wizard OR API. That way I can leverage ansible to MANUALLY make the changes that are currently made by the wizard when it is run.

For example:
The wizard creates a file 1.2.3.4.cfg and runs an mrtg command to start processing data......I would set up ansible to create that file and run the mrtg commands via ansible so that the end result is the same.

Does that help?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Leverage API to add/remove/update devices

Post by lmiltchev »

You could run the "Network Switch / Router" wizard, entering some "fake" data. This way, the wizard would show you a command that you could execute manually, for example:

Code: Select all

/usr/bin/cfgmaker --show-op-down --noreversedns --zero-speed '100000000' --enablesnmpv3 --snmp-options=:::::3 --username='username' --authprotocol='md5' --authpassword='authpassword' --privprotocol='des' --privpassword='privpassword' --contextengineid=0 '1.2.3.4'
Modify it by correcting the "fake" values, and run it from the CLI, redirecting it to a config file.

Example:

Code: Select all

/usr/bin/cfgmaker --show-op-down --noreversedns --zero-speed '100000000' --enablesnmpv3 --snmp-options=:::::3 --username='username' --authprotocol='md5' --authpassword='authpassword' --privprotocol='des' --privpassword='privpassword' --contextengineid=0 '1.2.3.4' > /etc/mrtg/conf.d/1.2.3.4.cfg
Modify permissions on the newly created file.

Code: Select all

chown apache.nagios /etc/mrtg/conf.d/1.2.3.4.cfg
chmod 775 /etc/mrtg/conf.d/1.2.3.4.cfg
Note:
BTW, if you wanted to add bunch of switches in bulk, the latest "Network Switch / Router" wizard (ver. 2.5.1) already provides this functionality.
example01.PNG
I am not sure if you knew that. If you however wanted to add switches from the CLI, then you could disregard this note. Thank you!

Hope this helps.
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
dfmco
Posts: 257
Joined: Wed Dec 04, 2013 11:05 am

Re: Leverage API to add/remove/update devices

Post by dfmco »

BRILLIANT! Thanks!

That is EXACTLY what I was looking for! So were do I see the commands that the wizard is sending? I don't think I have ever noticed that before. Is it on the GUI or in a log file perhaps?

My guess is that I could use the above method to capture any and all commands generated by a wizard which would be gold for what I am trying to do!

I had NO IDEA that there was a bulk add now. That may be a great interim solution. I will set this up in our test environment and see if that may also be a solution.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Leverage API to add/remove/update devices

Post by lmiltchev »

So were do I see the commands that the wizard is sending?
You will see it in the GUI, provided the command fails (caused by a wrong data, e.g. wrong IP, community string, protocol, password, etc.)

Example:
example01.PNG
I had NO IDEA that there was a bulk add now. That may be a great interim solution. I will set this up in our test environment and see if that may also be a solution.
Sure, let us know if you have any further questions. Thanks!
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked