-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
78 lines (60 loc) · 1.57 KB
/
functions.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
function reply($data) {
print json_encode($data, JSON_NUMERIC_CHECK);
exit();
}
function getServer($serverId) {
global $database;
$statement = $database->prepare(
'SELECT *
FROM `sm_servers`
WHERE `id` = :id
AND `enabled`'
);
$statement->execute([ 'id' => $serverId ]);
return $statement->fetch();
}
function getServerStatus($serverId) {
global $database;
$result = [];
foreach ([ 'PROCESSES', 'SESSIONS'] as $statusType) {
$statement = $database->prepare(
'SELECT
`created` AS `label`,
`value` AS `data`
FROM `sm_status_history`
WHERE `serverId` = :serverId
AND `type` = :type'
);
$statement->execute([
'serverId' => $serverId,
'type' => $statusType
]);
$result[strtolower($statusType)] = $statement->fetchAll();
}
return $result;
}
function saveServerStatus($serverId, $type, $value) {
global $database;
$statement = $database->prepare(
'INSERT INTO `sm_status_history` (
`serverId`,
`type`,
`value`
) VALUES (
:serverId,
:type,
:value
)'
);
$statement->execute([
'serverId' => $serverId,
'type' => $type,
'value' => $value
]);
return $statement->rowCount() > -1;
}
function getSnmpGaugeValue($gaugeData) {
return explode(' ', $gaugeData)[1];
}
?>