To add a free variable named
foo with value
bar to the host with ID 2 (
www.nagios.com in my case):
Code: Select all
use nagiosql;
insert into tbl_variabledefinition (name,value,last_modified) values ('foo','bar',NOW());
insert into tbl_lnkHostToVariabledefinition (idMaster, idSlave) values (2,6);
Adjust to your needs. The ID of 6 is because that is the sixth free var I have after adding it in the first insert:
Code: Select all
mysql> select * from tbl_variabledefinition;
+----+-----------+---------+---------------------+
| id | name | value | last_modified |
+----+-----------+---------+---------------------+
| 1 | _xiwizard | website | 2017-04-18 15:49:54 |
| 2 | _xiwizard | website | 2017-04-18 15:49:54 |
| 3 | _xiwizard | website | 2017-04-18 15:49:54 |
| 4 | _xiwizard | website | 2017-04-18 15:49:54 |
| 5 | _xiwizard | website | 2017-04-18 15:49:54 |
| 6 | foo | bar | 2017-05-10 12:43:47 |
+----+-----------+---------+---------------------+
6 rows in set (0.00 sec)
Code: Select all
mysql> select * from tbl_lnkHostToVariabledefinition;
+----------+---------+
| idMaster | idSlave |
+----------+---------+
| 2 | 1 |
| 2 | 6 |
+----------+---------+
You will want to dig into the following tables to get values:
Code: Select all
tbl_variabledefinition
tbl_lnkHostToVariabledefinition
tbl_lnkServiceToVariabledefinition
remembering that the Master and Slave IDs correspond to the table names, so in this example case:
Code: Select all
mysql> describe tbl_lnkHostToVariabledefinition;
+----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| idMaster | int(11) | NO | PRI | NULL | |
| idSlave | int(11) | NO | PRI | NULL | |
+----------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
idMaster refers to the Host ID since that appears first in the
tbl_lnkHostToVariabledefinition, and
idSlave refers to the variable ID since it appears second.
Use with caution, lemme know if you have questions (though strictly speaking direct DB manipulation is not covered).