Page 1 of 1
Leverage API to add/remove/update devices
Posted: Tue Aug 06, 2019 3:06 pm
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.
Re: Leverage API to add/remove/update devices
Posted: Wed Aug 07, 2019 1:20 pm
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.
Re: Leverage API to add/remove/update devices
Posted: Wed Aug 07, 2019 4:12 pm
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.
Re: Leverage API to add/remove/update devices
Posted: Thu Aug 08, 2019 10:35 am
by lmiltchev
As @jomann stated clearly:
Currently there is no way to run the wizard or set up mrtg-specific checks from the API.
Re: Leverage API to add/remove/update devices
Posted: Thu Aug 08, 2019 1:44 pm
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?
Re: Leverage API to add/remove/update devices
Posted: Thu Aug 08, 2019 2:07 pm
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.
Re: Leverage API to add/remove/update devices
Posted: Thu Aug 08, 2019 3:25 pm
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.
Re: Leverage API to add/remove/update devices
Posted: Thu Aug 08, 2019 3:44 pm
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!