Icinga / icinga2

The core of our monitoring platform with a powerful configuration language and REST API.
https://icinga.com/docs/icinga2/latest
GNU General Public License v2.0
2.03k stars 578 forks source link

Livestatus GET log host_name is empty if the host object has been deleted #5319

Closed gitmopp closed 7 years ago

gitmopp commented 7 years ago

Livestatus GET log does not return a host_name in some cases. In the example I changed the host_names. The length of the host_name is unchanged. I don' t have any special characters in the host_name.

Expected Behavior

GET log should return the host_name

Current Behavior

host_name is missing

Possible Solution

I didn' t look in the code.

Steps to Reproduce (for bugs)

The file /var/log/icinga2/compat/archives/icinga-06-01-2017-14.log shows the correct information:

[...]
[1496319600] CURRENT SERVICE STATE: ABCDE009;System Load;OK;HARD;1;OK - load average: 0.00, 0.03, 0.04
[1496319600] CURRENT SERVICE STATE: GHIJ432;CPU;OK;HARD;1;OK CPU Load ok.
[1496319600] CURRENT SERVICE STATE: XYZ12345;FS /tmp;OK;HARD;1;DISK OK - free space: /tmp 1749 MB (91% inode=99%):
[1496319600] CURRENT SERVICE STATE: XYZ12345;Bonding;OK;HARD;1;bond0 up on eth1: members = eth1 (up) eth0 (up)
[...]

When I run the Livequery I get

GET log
Columns: class time type state host_name service_description plugin_output message state_type contact_name
Filter: time = 1496319600
OutputFormat: csv

[...]
6;1496319600;CURRENT SERVICE STATE;0;ABCDE009;System Load;OK - load average: 0.00, 0.03, 0.04;[1496319600] CURRENT SERVICE STATE: ABCDE009;System Load;OK;HARD;1;OK - load average: 0.00, 0.03, 0.04;HARD;
6;1496319600;CURRENT SERVICE STATE;0;;CPU;OK CPU Load ok.;[1496319600] CURRENT SERVICE STATE: GHIJ432;CPU;OK;HARD;1;OK CPU Load ok.;HARD;
6;1496319600;CURRENT SERVICE STATE;0;XYZ12345;FS /tmp;DISK OK - free space: /tmp 1749 MB (91% inode=99%):;[1496319600] CURRENT SERVICE STATE: XYZ12345;FS /tmp;OK;HARD;1;DISK OK - free space: /tmp 1749 MB (91% inode=99%):;HARD;
6;1496319600;CURRENT SERVICE STATE;0;XYZ12345;Bonding;bond0 up on eth1: members = eth1 (up) eth0 (up);[1496319600] CURRENT SERVICE STATE: XYZ12345;Bonding;OK;HARD;1;bond0 up on eth1: members = eth1 (up) eth0 (up);HARD;
[...]

As you can see the host_name GHIJ432 is missing. It works for most other hosts.

Your Environment

gitmopp commented 7 years ago

From my understanding the problem is in lib/livestatus/logtable.cpp. return Service::GetByNamePair(host_name, service_description);

In lib/icinga/service.cpp: Service::GetByNamePair tries to return the value from host->GetServiceByShortName(serviceName)

GET log does not work if the host or service does not exist anymore in Icinga2 as an object. So if you delete a service from Icinga2 the GET log command will not return valid data.

dnsmichi commented 7 years ago

Problem here is that you'll need the object pointer for automatic table joins with additional attributes, if specified.

dnsmichi commented 7 years ago

Cannot be solved with the requirement of a valid object.