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.
where are custom macros located in mysql database
-
bheden
- Product Development Manager
- Posts: 179
- Joined: Thu Feb 13, 2014 9:50 am
- Location: Nagios Enterprises
Re: where are custom macros located in mysql database
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:
In Bash:
Hope this helps.
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';
Code: Select all
rm /usr/local/nagios/etc/hosts/localhost.cfg
cd /usr/local/nagiosxi/scripts/ && ./reconfigure_nagios.shAs of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Nagios Enterprises
Senior Developer
Nagios Enterprises
Senior Developer
Re: where are custom macros located in mysql database
bheden,
It works perfectly. Thank you for the information.
It works perfectly. Thank you for the information.
-
bheden
- Product Development Manager
- Posts: 179
- Joined: Thu Feb 13, 2014 9:50 am
- Location: Nagios Enterprises
Re: where are custom macros located in mysql database
You're welcome. Glad I could help. I'm going to lock the thread.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Nagios Enterprises
Senior Developer
Nagios Enterprises
Senior Developer