-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.php
341 lines (305 loc) · 12.7 KB
/
setup.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2018 Mark Brugnoli-Vinten |
| |
| 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. |
+-------------------------------------------------------------------------+
| https://www.github.com/netniv/plugin_tholdlists |
+-------------------------------------------------------------------------+
*/
include_once(dirname(__FILE__) . '/functions.php');
function plugin_tholdlists_install() {
api_plugin_register_hook('tholdlists', 'config_arrays', 'tholdlists_config_arrays', 'setup.php');
api_plugin_register_hook('tholdlists', 'draw_navigation_text', 'tholdlists_draw_navigation_text', 'setup.php');
api_plugin_register_hook('tholdlists', 'poller_bottom', 'tholdlists_poller_bottom', 'setup.php');
api_plugin_register_realm('tholdlists', 'tholdlists.php', __('THold Notification Lists Settings', 'tholdlists'), 1);
tholdlists_setup_table();
}
function plugin_tholdlists_uninstall() {
db_execute('DROP TABLE mbv_thold_lists');
return true;
}
function plugin_tholdlists_check_config() {
return true;
}
function plugin_tholdlists_version() {
global $config;
$info = parse_ini_file($config['base_path'] . '/plugins/tholdlists/INFO', true);
return $info['info'];
}
function tholdlists_poller_bottom() {
global $config;
if ($config['poller_id'] == 1) {
$imports = db_fetch_assoc('SELECT * FROM mbv_thold_lists WHERE enabled="on"');
if (sizeof($imports)) {
$command_string = read_config_option('path_php_binary');
$extra_args = '-q "' . $config['base_path'] . '/plugins/tholdlists/poller_import.php"';
exec_background($command_string, $extra_args);
}
}
}
function tholdlists_check_upgrade() {
global $config, $database_default;
include_once($config['library_path'] . '/database.php');
include_once($config['library_path'] . '/functions.php');
// Let's only run this check if we are on a page that actually needs the data
$files = array('plugins.php', 'tholdlists.php');
if (!in_array(get_current_page(), $files)) {
return;
}
$info = plugin_tholdlists_version();
$current = $info['version'];
$old = db_fetch_cell("SELECT version FROM plugin_config WHERE directory='tholdlists'");
tholdlists_create_table();
if (cacti_version_compare($old, $current, '<')) {
if (cacti_version_compare($old, '1.0.1', '<')) {
db_execute('ALTER TABLE `mbv_thold_lists` ADD COLUMN `import_exclude` VARCHAR(2048) DEFAULT \'\' AFTER `import_type`');
}
}
if ($current != $old) {
if (api_plugin_is_enabled('tholdlists')) {
# may sound ridiculous, but enables new hooks
api_plugin_enable_hooks('tholdlists');
}
db_execute("UPDATE plugin_config
SET version='$current'
WHERE directory='tholdlists'");
db_execute("UPDATE plugin_config SET
version='" . $info['version'] . "',
name='" . $info['longname'] . "',
author='" . $info['author'] . "',
webpage='" . $info['homepage'] . "'
WHERE directory='" . $info['name'] . "' ");
}
}
function tholdlists_check_dependencies() {
return true;
}
function tholdlists_setup_table() {
global $config, $database_default;
include_once($config['library_path'] . '/database.php');
tholdlists_create_table();
return true;
}
function tholdlists_create_table() {
if (!db_table_exists('mbv_thold_lists')) {
db_execute("CREATE TABLE `mbv_thold_lists` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT '',
`enabled` char(3) DEFAULT 'on',
`import_prefix` varchar(255) DEFAULT '',
`import_file` varchar(255) DEFAULT '',
`import_timing` varchar(20) DEFAULT 'disabled',
`import_skip` int(10) unsigned DEFAULT '0',
`import_hourly` varchar(20) DEFAULT '',
`import_daily` varchar(20) DEFAULT '',
`import_clear` char(3) DEFAULT '',
`import_thold` char(3) DEFAULT '',
`import_type` int(10) unsigned DEFAULT '0',
`status` int(10) unsigned DEFAULT '0',
`import_pid` int(10) unsigned DEFAULT NULL,
`next_start` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_checked` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_started` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_ended` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_errored` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`last_runtime` double NOT NULL DEFAULT '0',
`last_error` varchar(255) DEFAULT NULL,
`total_items` double DEFAULT '0',
PRIMARY KEY (`id`))
ENGINE=InnoDB
COMMENT='Stores THold Notification List Import Settings for Cacti'");
}
if (!db_table_exists('mbv_thold_lists_contacts')) {
db_execute("CREATE TABLE `mbv_thold_lists_contacts` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`tholdlist_id` int(10) unsigned NOT NULL DEFAULT '0',
`list_id` int(10) unsigned NOT NULL DEFAULT '0',
`name` varchar(255) DEFAULT '',
`graph_ids` varchar(4000) DEFAULT '',
`date_imported` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`date_inserted` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`))
ENGINE=InnoDB
COMMENT='Stores THoldList Contacts, links to list and groups'");
}
return true;
}
function tholdlists_config_arrays() {
global $menu, $fields_tholdlists_import_edit, $messages, $config, $tholdlists_import_type_names;
/* perform database upgrade, if required */
tholdlists_check_upgrade();
$dir = dir($config['base_path'] . '/include/themes/');
while (false !== ($entry = $dir->read())) {
if ($entry != '.' && $entry != '..') {
if (is_dir($config['base_path'] . '/include/themes/' . $entry)) {
$themes[$entry] = ucwords($entry);
}
}
}
asort($themes);
$dir->close();
// Replace OS check and fixed temp dir with sys_get_temp_dir()
$tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR;
if (isset($_SESSION['tholdlists_message']) && $_SESSION['tholdlists_message'] != '') {
$messages['tholdlists_message'] = array('message' => $_SESSION['tholdlists_message'], 'type' => 'info');
}
$menu[__('Management', 'tholdlists')]['plugins/tholdlists/tholdlists.php'] = __('Notification List Imports', 'tholdlists');
$fields_tholdlists_import_edit = array(
'tholdlists_hdr_general' => array(
'friendly_name' => __('General', 'tholdlists'),
'collapsible' => 'true',
'method' => 'spacer'
),
'name' => array(
'friendly_name' => __('Notification List Import Name', 'tholdlists'),
'description' => __('The name of this notification list import.', 'tholdlists'),
'method' => 'textbox',
'value' => '|arg1:name|',
'default' => 'New Notification List Import',
'max_length' => '64',
'size' => '40'
),
'enabled' => array(
'friendly_name' => __('Enabled', 'tholdlists'),
'description' => __('Check this Checkbox if you wish this notification list import to be enabled.', 'tholdlists'),
'value' => '|arg1:enabled|',
'default' => 'on',
'method' => 'checkbox'
),
'import_clear' => array(
'friendly_name' => __('Clear', 'tholdlists'),
'description' => __('Check this Checkbox if you wish to clear matching notification lists during import.', 'tholdlists'),
'value' => '|arg1:import_clear|',
'method' => 'checkbox'
),
'import_hdr_paths' => array(
'friendly_name' => __('Import Information', 'tholdlists'),
'collapsible' => 'true',
'method' => 'spacer'
),
'import_thold' => array(
'friendly_name' => __('Update Threshold', 'tholdlists'),
'description' => __('Check this Checkbox if you wish to update matching thresholds during import.', 'tholdlists'),
'value' => '|arg1:import_thold|',
'method' => 'checkbox'
),
'import_type' => array(
'friendly_name' => __('Import Field', 'tholdlists'),
'description' => __('This is the field to update on the Threshold, it will be set to the imported notification list', 'tholdlists'),
'method' => 'drop_array',
'value' => '|arg1:import_type|',
'array' => $tholdlists_import_type_names
),
'import_file' => array(
'friendly_name' => __('Import File', 'tholdlists'),
'description' => __('This is the file that will contain the exported data that needs importing.', 'tholdlists'),
'method' => 'textbox',
'value' => '|arg1:import_file|',
'max_length' => '255'
),
'import_prefix' => array(
'friendly_name' => __('Import Prefix', 'tholdlists'),
'description' => __('This is the string that will prefix the name of the notification list name in the import file', 'tholdlists'),
'method' => 'textbox',
'value' => '|arg1:import_prefix|',
'max_length' => '255'
),
'import_exclude' => array(
'friendly_name' => __('Templates to exclude', 'tholdlists'),
'description' => __('If you want Cacti to ignore certain threshold templates, select them here'),
'method' => 'drop_multi',
'size' => '50',
'value' => '|arg1:import_exclude|',
'array' => '|arg2:templates|',
'default' => ''
),
'import_hdr_timing' => array(
'friendly_name' => __('Import Timing', 'tholdlists'),
'method' => 'spacer',
'collapsible' => 'true',
),
'import_timing' => array(
'friendly_name' => __('Timing Method', 'tholdlists'),
'description' => __('Choose when to Import Graphs.', 'tholdlists'),
'method' => 'drop_array',
'value' => '|arg1:import_timing|',
'default' => 'import_hourly',
'array' => array(
'periodic' => __('Periodic', 'tholdlists'),
'hourly' => __('Hourly', 'tholdlists'),
'daily' => __('Daily', 'tholdlists')
)
),
'import_skip' => array(
'friendly_name' => __('Periodic Import Cycle', 'tholdlists'),
'description' => __('How often do you wish Cacti to Import Graphs. This is the unit of Polling Cycles you wish to activate the import.', 'tholdlists'),
'method' => 'drop_array',
'value' => '|arg1:import_skip|',
'array' => array(
1 => __('Every Polling Cycle', 'tholdlists'),
2 => __('Every %d Polling Cycles', 2, 'tholdlists'),
3 => __('Every %d Polling Cycles', 3, 'tholdlists'),
4 => __('Every %d Polling Cycles', 4, 'tholdlists'),
5 => __('Every %d Polling Cycles', 5, 'tholdlists'),
6 => __('Every %d Polling Cycles', 6, 'tholdlists'),
7 => __('Every %d Polling Cycles', 7, 'tholdlists'),
8 => __('Every %d Polling Cycles', 8, 'tholdlists'),
9 => __('Every %d Polling Cycles', 9, 'tholdlists'),
10 => __('Every %d Polling Cycles', 10, 'tholdlists'),
11 => __('Every %d Polling Cycles', 11, 'tholdlists'),
12 => __('Every %d Polling Cycles', 12, 'tholdlists')
)
),
'import_hourly' => array(
'friendly_name' => __('Hourly at specified minutes', 'tholdlists'),
'description' => __('If you want Cacti to import on an hourly basis, put the minutes of the hour when to do that. Cacti assumes that you run the data gathering script every 5 minutes, so it will round your value to the one closest to its runtime. For instance, 43 would equal 40 minutes past the hour.', 'tholdlists'),
'method' => 'textbox',
'placeholder' => 'MM',
'value' => '|arg1:import_hourly|',
'default' => '00',
'max_length' => '10',
'size' => '5'
),
'import_daily' => array(
'friendly_name' => __('Daily at specified time', 'tholdlists'),
'description' => __('If you want Cacti to import on an daily basis, put here the time to do that. Cacti assumes that you run the data gathering script every poller internal, so it will round your value to the one closest to its runtime. For instance, 21:23 would equal 20 minutes after 9 PM.', 'tholdlists'),
'method' => 'textbox',
'placeholder' => 'HH:MM',
'value' => '|arg1:import_daily|',
'default' => '00:00',
'max_length' => '10',
'size' => '5'
),
);
}
function tholdlists_draw_navigation_text($nav) {
$nav['tholdlists.php:'] = array(
'title' => __('THold Notification List Import', 'tholdlists'),
'mapping' => 'index.php:',
'url' => 'tholdlists.php',
'level' => '1'
);
$nav['tholdlists.php:edit'] = array(
'title' => __('(Edit)', 'tholdlists'),
'mapping' => 'index.php:,tholdlists.php:',
'url' => '',
'level' => '2'
);
$nav['tholdlists.php:actions'] = array(
'title' => __('Actions', 'tholdlists'),
'mapping' => 'index.php:,tholdlists.php:',
'url' => '',
'level' => '2'
);
return $nav;
}