Page 1 of 1

where are custom macros located in mysql database

Posted: Wed Mar 16, 2016 8:52 am
by tbyrne
Hello,

I am working on a Wake On Lan script that requires MAC address of a host to work. Because we use DHCP for our workstations I needed to write another script to find a hosts mac address using snmp. I now need to add the mac address to each host and would like to do it with a custom macro. Does anyone know how I can add a custom macro to a host using a script? I figure there has to be a way to add this information in to mysql database programmatically.

Re: where are custom macros located in mysql database

Posted: Wed Mar 16, 2016 9:31 am
by bheden
I generally recommend against writing directly to the SQL database. With that being said, here is the information you require.

In the nagiosql database, the following tables are of interest here:

tbl_host
tbl_variabledefinition
tbl_lnkHostToVariabledefinition

So, as an example for Nagios host localhost, with a MAC Address of 00:00:00:00:00:00, the following snippets should work just fine..

In MySQL:

Code: Select all

INSERT INTO tbl_variabledefinition (name, value, last_modified) VALUES ('_macaddress', '00:00:00:00:00:00', NOW());
INSERT INTO tbl_lnkHostToVariabledefinition(idMaster, idSlave) VALUES ((SELECT id FROM tbl_host WHERE host_name = 'localhost' LIMIT 1), (SELECT LAST_INSERT_ID()));
UPDATE tbl_host SET use_variables = 1 WHERE host_name = 'localhost';
In Bash:

Code: Select all

rm /usr/local/nagios/etc/hosts/localhost.cfg
cd /usr/local/nagiosxi/scripts/ && ./reconfigure_nagios.sh
Hope this helps.

Re: where are custom macros located in mysql database

Posted: Wed Mar 16, 2016 2:11 pm
by tbyrne
bheden,

It works perfectly. Thank you for the information.

Re: where are custom macros located in mysql database

Posted: Wed Mar 16, 2016 3:01 pm
by bheden
You're welcome. Glad I could help. I'm going to lock the thread.