Thanks @yosiasz, I appreciate your assistance here as well.
You had originally asked for more detail on the data. so I have posted below, but I will also try your example and see if that answers my question and gets me to my goal…
Sample Table:
CREATE TABLE sensorlogs (
Hostname Varchar(40), – Hostname or IP
Sensor Varchar(40), – Sensor Description
Mode Int, – Mode of communication delivering sensor status, SNMP, Ping, Syslog, eventlog, etc. 5.
Status Int, – Status depends on Mode
UpdateTimeUTC Datetime – Datetime of record entry
)
Sample Data:
Insert Into sensorlogs (Hostname, Sensor, Mode, Status, UpdatetimeUTC ) Values (‘TestHost’,‘Sensor1’,5,1,‘2022-12-02 01:00:00.000’)
Insert Into sensorlogs (Hostname, Sensor, Mode, Status, UpdatetimeUTC ) Values (‘TestHost’,‘Sensor1’,5,2,‘2022-12-02 02:00:00.000’)
Insert Into sensorlogs (Hostname, Sensor, Mode, Status, UpdatetimeUTC ) Values (‘TestHost’,‘Sensor1’,5,3,‘2022-12-02 03:00:00.000’)
Insert Into sensorlogs (Hostname, Sensor, Mode, Status, UpdatetimeUTC ) Values (‘TestHost’,‘Sensor1’,5,4,‘2022-12-02 04:00:00.000’)
Insert Into sensorlogs (Hostname, Sensor, Mode, Status, UpdatetimeUTC ) Values (‘TestHost’,‘Sensor1’,5,1,‘2022-12-02 05:00:00.000’)
Insert Into sensorlogs (Hostname, Sensor, Mode, Status, UpdatetimeUTC ) Values (‘TestHost’,‘Sensor1’,5,2,‘2022-12-02 06:00:00.000’)
Insert Into sensorlogs (Hostname, Sensor, Mode, Status, UpdatetimeUTC ) Values (‘TestHost’,‘Sensor1’,5,1,‘2022-12-02 07:00:00.000’)
And my current Query to test 1 sensor on 1 hostname:
Select HostName, count(*) As Value, – Hostname should be self explanatory, Value is a count of the Status 1& 2 for Mode 5 over a 7 day period.
Sensor As metric, – Only labeled as metric as a test to see if the column name made any difference to the functionality of the panel based on an example I saw somewhere.
DATEDIFF(s,‘19700101 05:00:00:000’,getdate()) As time – I’m not concerned about time for this particular status, just the number of times it’s been out for this particular metric.
Where Hostname = ‘testHost’ – This is just for testing a single sensor on a single host right now, there is other data in the table currently
And (Status NOT IN (3,4)) And (Mode = 5) – Only looking for mode 5 and any status other then 3/4
Group by Hostname – I would imagine this would end up grouping by Hostname and Sensor in the end.
And lastly, hopefully a decent explanation of the data and our goal:
In our example, we are looking at a single Sensor, ‘Sensor1’ for TestHost
The mode of the sensor is 5 which is a syslog message giving an up/down/trouble state for a windows service.
The down status is 1, trouble is 2 and up is 3, 4 is out of service which is why it was also excluded from the result set in the query.
The end result goal is to have a different box in the Status Panel for each hostname monitored and per the description of the Status Panel regarding
its capabilities, Green if all is good, Orange if sensors are outside of threshold and RED if ALL sensors are outside of threshold.