-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraylogstatusapi.php
42 lines (34 loc) · 1.09 KB
/
graylogstatusapi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
function getGraylogServiceStatus() : string {
if (strpos(shell_exec("systemctl status graylog-server.service | grep Active"), "running") !== false) {
return "UP";
}
return "DOWN";
}
function getMongoDbServiceStatus() :string {
if (strpos(shell_exec("systemctl status mongod.service | grep Active"), "running") !== false) {
return "UP";
}
return "DOWN";
}
function getElasticsearchServiceStatus() : string {
if (strpos(shell_exec("systemctl status elasticsearch.service | grep Active"), "running") !== false) {
return "UP";
}
return "DOWN";
}
function getDiskUsagePercent() : float {
return doubleval(shell_exec("df -h | grep sda | awk {'print $5'}"));
}
function getDiskUsage() : string {
return trim(shell_exec("df -h | grep sda | awk {'print $3'}"));
}
$status = [
"graylog" => getGraylogServiceStatus(),
"mongodb" => getMongoDbServiceStatus(),
"elasticsearch" => getElasticsearchServiceStatus(),
"diskusage" => getDiskUsage(),
"diskusagepercent" => getDiskUsagePercent()
];
echo json_encode($status);
?>