Hi,
You can do this with a shell script making API calls. Below is some code and some psuedo-code:
Code: Select all
curl -s -XGET "http://192.168.23.82/nagiosxi/api/v1/objects/host?apikey=ZrtHUhtGlfEaQDhTe8FKXY9k3bet2DCViQn0oEcBR3WBOJd8kmb2WnJG80cbQrop&pretty=1R" | grep host_name > hosts.txt
curl -s -XGET "http://192.168.23.82/nagiosxi/api/v1/objects/hoststatus?apikey=ZrtHUhtGlfEaQDhTe8FKXY9k3bet2DCViQn0oEcBR3WBOJd8kmb2WnJG80cbQrop&pretty=1" | grep last_check >hostcheck.txt
cut -f 1 hostcheck.txt | paste hosts.txt - > hoststatus.txt
here is the output:
Code: Select all
cat hoststatus.txt
"host_name": "Nagios Monitor host name", "last_check": "2021-04-19 15:32:03",
"host_name": "192.168.23.81", "last_check": "2021-04-19 15:32:54",
For each line in hosts.txt:
Code: Select all
curl -s -XGET "http://192.168.23.82/nagiosxi/api/v1/objects/servicestatus apikey=ZrtHUhtGlfEaQDhTe8FKXY9k3bet2DCViQn0oEcBR3WBOJd8kmb2WnJG80cbQrop&pretty=1" | grep service_description > services.txt
curl -s -XGET "http://192.168.23.82/nagiosxi/api/v1/objects/servicestatus?apikey=ZrtHUhtGlfEaQDhTe8FKXY9k3bet2DCViQn0oEcBR3WBOJd8kmb2WnJG80cbQrop&pretty=1" | grep status_update_time > servicecheck.txt
cut -f 1 servicecheck.txt | paste services.txt - > servicestatus[for-loop index number].txt
next host
here is the output of one host's servicestatus.txt:
Code: Select all
cat servicestatus0.txt
"service_description": "SSH", "status_update_time": "2021-04-19 15:59:37",
"service_description": "Total Processes", "status_update_time": "2021-04-19 16:01:37",
"service_description": "Swap Usage", "status_update_time": "2021-04-19 16:01:22",
"service_description": "Service Status - mysqld", "status_update_time": "2021-04-19 16:01:09",
"service_description": "Service Status - httpd", "status_update_time": "2021-04-19 16:00:40",
"service_description": "Current Load", "status_update_time": "2021-04-19 15:57:20",
"service_description": "Current Users", "status_update_time": "2021-04-19 15:57:46",
"service_description": "HTTP", "status_update_time": "2021-04-19 15:58:10",
"service_description": "Memory Usage", "status_update_time": "2021-04-19 15:58:22",
"service_description": "PING", "status_update_time": "2021-04-19 15:59:11",
"service_description": "Root Partition", "status_update_time": "2021-04-19 15:59:28",
"service_description": "Service Status - crond", "status_update_time": "2021-04-19 16:00:16",
"service_description": "CPU Usage", "status_update_time": "2021-04-19 15:56:52",
"service_description": "User Count", "status_update_time": "2021-04-19 15:58:44",
"service_description": "Disk Usage on \/", "status_update_time": "2021-04-19 15:58:49",
"service_description": "Ping", "status_update_time": "2021-04-19 15:59:19",
"service_description": "Total Processes", "status_update_time": "2021-04-19 15:59:55",
Now that you have all the data, you need some code that checks the dates and times in the data files against today's date
to see if the data is more than a week old. If it is send email.
Thanks