where are custom macros located in mysql database

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
tbyrne
Posts: 39
Joined: Tue Oct 21, 2014 2:02 pm
Location: Bohemia NY

where are custom macros located in mysql database

Post 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.
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

Post 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.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Nagios Enterprises
Senior Developer
tbyrne
Posts: 39
Joined: Tue Oct 21, 2014 2:02 pm
Location: Bohemia NY

Re: where are custom macros located in mysql database

Post by tbyrne »

bheden,

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

Post by bheden »

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
Locked