-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
99 lines (82 loc) · 3.5 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2021-2024 Petr Macek |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| https://github.com/xmacan/ |
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
function uptime_get_allowed_devices($user_id, $array = false) {
$x = 0;
$us = read_user_setting('hide_disabled', false, false, $user_id);
if ($us == 'on') {
set_user_setting('hide_disabled', '', $user_id);
}
$allowed = get_allowed_devices('', 'null', -1, $x, $user_id);
if ($us == 'on') {
set_user_setting('hide_disabled', 'on', $user_id);
}
if (cacti_count($allowed)) {
if ($array) {
return(array_column($allowed, 'id'));
}
return implode(',', array_column($allowed, 'id'));
} else {
return false;
}
}
function uptime_display_events($host_id) {
if (!in_array($host_id, uptime_get_allowed_devices ($_SESSION['sess_user_id'], true))) {
print 'You haven\'t permission for ' . $host_id;
return false;
}
if (basename($_SERVER['PHP_SELF']) == 'uptime_tab.php') {
$limit = 1000;
$text= '';
} else {
$limit = 20;
$text = '(last 20 events)';
}
html_start_box('<strong>Uptime/restart history ' . $text . '</strong>', '100%', '', '3', 'center', '');
print "<tr class='tableHeader'><th>Date</th><th>Flag</th><th>Info</th></tr>";
$records = db_fetch_assoc_prepared ('SELECT * FROM plugin_uptime_data
WHERE host_id = ?
ORDER BY id DESC LIMIT ' . $limit,
array($host_id));
if (cacti_sizeof ($records) > 0) {
$i = 0;
foreach ($records as $record) {
$i++;
form_alternate_row("x$i", true);
print "<td class='nowrap'>" . date('Y-m-d H:i',$record['timestamp']) . '</td>';
print "<td class='nowrap'>" . $record['state'] . '</td>';
print "<td class='nowrap'>" . $record['info'] . '</td>';
form_end_row();
}
$count = db_fetch_cell_prepared ("SELECT count(*) FROM host
WHERE disabled != 'on' AND id = ? AND availability_method IN (1,2,5,6)",
array($host_id));
if ($count == 0) {
print '<br/><b>For uptime plugin you have to choose any SNMP availability option</b><br/>';
}
} else {
print '<tr><td colspan=3>No data</td></tr>';
}
html_end_box(false);
}