-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsetup.php
More file actions
1000 lines (920 loc) · 40 KB
/
Copy pathsetup.php
File metadata and controls
1000 lines (920 loc) · 40 KB
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| 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. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
/**
* Return the CSP nonce attribute for inline <script> tags, safely across
* Cacti versions. Newer Cacti releases enforce a Content-Security-Policy that
* requires a per-request nonce on parser-inserted scripts; older releases lack
* the CactiSecureHeaders class, so this returns an empty string there.
*
* @return string The nonce attribute when supported, otherwise empty string.
*/
function plugin_hmib_csp_nonce(): string {
if (class_exists('CactiSecureHeaders')) {
return CactiSecureHeaders::getNonceAttribute();
}
return '';
}
/**
* Plugin install hook: registers all of this plugin's Cacti hooks
* (config arrays/settings, navigation text, poller_bottom, header tabs,
* and its CPU/disk/CPU-index data-provider hooks used by other
* plugins), registers its two admin realms, and creates its database
* tables. Called by Cacti's plugin architecture when the plugin is
* installed.
*
* @return void
*/
function plugin_hmib_install(): void {
// graph setup all arrays needed for automation
api_plugin_register_hook('hmib', 'config_arrays', 'hmib_config_arrays', 'setup.php');
api_plugin_register_hook('hmib', 'config_settings', 'hmib_config_settings', 'setup.php');
api_plugin_register_hook('hmib', 'draw_navigation_text', 'hmib_draw_navigation_text', 'setup.php');
api_plugin_register_hook('hmib', 'poller_bottom', 'hmib_poller_bottom', 'setup.php');
api_plugin_register_hook('hmib', 'top_header_tabs', 'hmib_show_tab', 'setup.php');
api_plugin_register_hook('hmib', 'top_graph_header_tabs', 'hmib_show_tab', 'setup.php');
api_plugin_register_hook('hmib', 'hmib_get_cpu', 'hmib_get_cpu', 'setup.php');
api_plugin_register_hook('hmib', 'hmib_get_cpu_indexes', 'hmib_get_cpu_indexes', 'setup.php');
api_plugin_register_hook('hmib', 'hmib_get_disk', 'hmib_get_disk', 'setup.php');
api_plugin_register_realm('hmib', 'hmib.php', __('Host MIB Viewer', 'hmib'), 1);
api_plugin_register_realm('hmib', 'hmib_types.php', __('Host MIB Admin', 'hmib'), 1);
hmib_setup_table();
}
/**
* Plugin uninstall hook: drops all of this plugin's database tables.
* Called by Cacti's plugin architecture when the plugin is
* uninstalled.
*
* @return void
*/
function plugin_hmib_uninstall(): void {
// Do any extra Uninstall stuff here
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrDevices`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrSWInstalled`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrProcessor`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrStorage`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrSWRun`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrSWRun_ignore`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrSWRun_last_seen`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrSystem`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_hrSystemTypes`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_processes`');
db_execute('DROP TABLE IF EXISTS `plugin_hmib_types`');
}
/**
* Plugin config-check hook: ensures the plugin's schema/hooks are up to
* date by delegating to hmib_check_upgrade(). Called by Cacti's plugin
* architecture on relevant page loads.
*
* @return bool Always true.
*/
function plugin_hmib_check_config(): bool {
// Here we will check to ensure everything is configured
hmib_check_upgrade();
return true;
}
/**
* Plugin upgrade hook: brings the plugin's schema/hooks up to date by
* delegating to hmib_check_upgrade(). Called by Cacti's plugin
* architecture when the plugin is upgraded to a new version.
*
* @return bool Always true.
*/
function plugin_hmib_upgrade(): bool {
// Here we will upgrade to the newest version
hmib_check_upgrade();
return true;
}
/**
* Reads and returns this plugin's version/author/metadata info from its
* INFO file. Called throughout this plugin (e.g. display_version() in
* the poller scripts, hmib_check_upgrade()) wherever plugin metadata is
* needed.
*
* @return array The plugin's info array, as parsed from the INFO file's
* '[info]' section.
*
* @global array $config Cacti global configuration array; used to
* locate the plugin's INFO file.
*/
function plugin_hmib_version(): array {
global $config;
$info = parse_ini_file($config['base_path'] . '/plugins/hmib/INFO', true);
if (!is_array($info) || !isset($info['info']) || !is_array($info['info'])) {
return [];
}
return $info['info'];
}
/**
* Checks whether the plugin's recorded database version differs from
* its actual (INFO file) version and, if so, re-enables its hooks,
* updates the plugin_config record, applies any needed incremental
* schema changes (e.g. adding the hrSWRun_last_seen.total_time column),
* and clears a stale config_form hook registration. Only runs on
* plugins.php/hmib.php page loads. Called from
* plugin_hmib_check_config() and plugin_hmib_upgrade().
*
* @return void
*
* @global array $config Cacti global configuration array;
* used to include required libraries.
* @global mixed $database_default Reserved/declared for parity with
* other setup functions; not used
* directly here.
*/
function hmib_check_upgrade(): void {
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 = ['plugins.php', 'hmib.php'];
if (!in_array(get_current_page(), $files, true)) {
return;
}
$info = plugin_hmib_version();
$current = $info['version'];
$old = db_fetch_cell("SELECT version FROM plugin_config WHERE directory='hmib'");
if ($current != $old) {
if (api_plugin_is_enabled('hmib')) {
// may sound ridiculous, but enables new hooks
api_plugin_enable_hooks('hmib');
}
db_execute("UPDATE plugin_config SET version='$current' WHERE directory='hmib'");
db_execute("UPDATE plugin_config SET
version='" . $info['version'] . "',
name='" . $info['longname'] . "',
author='" . $info['author'] . "',
webpage='" . $info['homepage'] . "'
WHERE directory='" . $info['name'] . "' ");
if (!db_column_exists('plugin_hmib_hrSWRun_last_seen', 'total_time')) {
db_execute("ALTER TABLE plugin_hmib_hrSWRun_last_seen
ADD COLUMN `total_time` BIGINT unsigned not null default '0' AFTER `name`");
}
db_execute('DELETE FROM plugin_hooks WHERE name="hmib" AND hook="config_form"');
}
}
/**
* Reports whether this plugin's dependencies are satisfied. Called by
* Cacti's plugin architecture when checking whether the plugin can be
* enabled.
*
* @return bool Always true (this plugin declares no extra
* dependencies).
*/
function hmib_check_dependencies(): bool {
return true;
}
/**
* Creates (if not already present) all of this plugin's database
* tables: plugin_hmib_hrDevices and the other Host Resources data
* tables, type/system tables, and the process-lock table. Called from
* plugin_hmib_install().
*
* @return void
*
* @global array $config Cacti global configuration array;
* used to include the database library.
* @global mixed $database_default Reserved/declared for parity with
* other setup functions; not used
* directly here.
*/
function hmib_setup_table(): void {
global $config, $database_default;
include_once($config['library_path'] . '/database.php');
db_execute("CREATE TABLE IF NOT EXISTS `plugin_hmib_hrDevices` (
`host_id` int(10) unsigned NOT NULL,
`index` int(10) unsigned NOT NULL,
`type` int(10) unsigned NOT NULL DEFAULT '1',
`description` varchar(255) NOT NULL DEFAULT '',
`status` int(10) unsigned NOT NULL DEFAULT '0',
`errors` int(10) unsigned NOT NULL DEFAULT '0',
`present` tinyint(3) unsigned NOT NULL DEFAULT '1',
PRIMARY KEY (`host_id`,`index`),
INDEX `description` (`description`),
INDEX `index` (`index`))
ENGINE=MyISAM
COMMENT='Stores Device Information';");
db_execute("CREATE TABLE IF NOT EXISTS `plugin_hmib_hrSWInstalled` (
`host_id` int(10) unsigned NOT NULL,
`index` int(10) unsigned NOT NULL,
`name` varchar(255) NOT NULL default '',
`type` int(10) unsigned NOT NULL default '1',
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`present` tinyint(3) unsigned NOT NULL default '1',
PRIMARY KEY (`host_id`,`index`),
INDEX `name` (`name`),
INDEX `index` (`index`))
ENGINE=MyISAM
COMMENT='Catalogue of Installed Software';");
db_execute("CREATE TABLE IF NOT EXISTS `plugin_hmib_hrProcessor` (
`host_id` int(10) unsigned NOT NULL,
`index` int(10) unsigned NOT NULL,
`load` int(10) unsigned NOT NULL default '0',
`present` tinyint(3) unsigned NOT NULL default '1',
PRIMARY KEY (`host_id`,`index`),
INDEX `index` (`index`))
ENGINE=MyISAM
COMMENT='Stores Processor Information';");
db_execute("CREATE TABLE IF NOT EXISTS `plugin_hmib_hrStorage` (
`host_id` int(10) unsigned NOT NULL,
`index` int(10) unsigned NOT NULL,
`type` int(10) unsigned NOT NULL default '1',
`description` varchar(255) NOT NULL default '',
`allocationUnits` int(10) unsigned NOT NULL default '0',
`size` int(10) unsigned NOT NULL default '0',
`used` int(10) unsigned NOT NULL default '0',
`failures` int(10) unsigned NOT NULL default '0',
`present` tinyint(3) unsigned NOT NULL default '1',
PRIMARY KEY (`host_id`,`index`),
INDEX `description` (`description`),
INDEX `index` (`index`))
ENGINE=MyISAM
COMMENT='Stores the Storage Information';");
db_execute("CREATE TABLE IF NOT EXISTS `plugin_hmib_hrSWRun` (
`host_id` int(10) unsigned NOT NULL,
`index` int(10) unsigned NOT NULL,
`name` varchar(64) NOT NULL default '',
`path` varchar(255) NOT NULL default '',
`parameters` varchar(255) NOT NULL default '',
`type` int(10) unsigned NOT NULL default '1',
`status` int(10) unsigned NOT NULL default '0',
`perfCPU` int(10) unsigned NOT NULL default '0',
`perfMemory` int(10) unsigned NOT NULL default '0',
`present` tinyint(3) unsigned NOT NULL default '1',
PRIMARY KEY (`index`,`host_id`),
INDEX `name` (`name`),
INDEX `index` (`index`))
ENGINE=MyISAM
COMMENT='Displays Running Process Information';");
db_execute("CREATE TABLE IF NOT EXISTS `plugin_hmib_hrSWRun_last_seen` (
`host_id` int(10) unsigned NOT NULL,
`name` varchar(64) NOT NULL,
`total_time` bigint(20) unsigned NOT NULL default '0',
`last_seen` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`host_id`, `name`),
INDEX `name` (`name`))
ENGINE=MyISAM
COMMENT='Displays when a binary was last seen running on the host';");
db_execute("CREATE TABLE IF NOT EXISTS `plugin_hmib_hrSystem` (
`host_id` int(10) unsigned NOT NULL,
`host_type` int(10) unsigned NOT NULL default '0',
`host_status` int(10) unsigned NOT NULL default '0',
`uptime` int(10) unsigned NOT NULL default '0',
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`initLoadDevice` int(10) unsigned NOT NULL default '0',
`initLoadParams` varchar(255) NOT NULL default '',
`users` int(10) unsigned NOT NULL default '0',
`cpuPercent` int(10) unsigned NOT NULL default '0',
`numCpus` int(10) unsigned NOT NULL default '0',
`processes` int(10) unsigned NOT NULL default '0',
`maxProcesses` int(10) unsigned NOT NULL default '0',
`memSize` BIGINT unsigned NOT NULL default '0',
`memUsed` FLOAT NOT NULL default '0',
`swapSize` BIGINT UNSIGNED NOT NULL default '0',
`swapUsed` FLOAT NOT NULL default '0',
`sysDescr` varchar(255) NOT NULL default '',
`sysObjectID` varchar(128) NOT NULL default '',
`sysUptime` int(10) unsigned NOT NULL default '0',
`sysName` varchar(64) NOT NULL default '',
`sysContact` varchar(128) NOT NULL default '',
`sysLocation` varchar(255) NOT NULL default '',
PRIMARY KEY (`host_id`),
INDEX `host_type` (`host_type`),
INDEX `host_status` (`host_status`))
ENGINE=MyISAM
COMMENT='Contains all Hosts that support hostMib';");
db_execute("CREATE TABLE IF NOT EXISTS `plugin_hmib_processes` (
`pid` int(10) unsigned NOT NULL,
`taskid` int(10) unsigned NOT NULL,
`started` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`pid`))
ENGINE=MEMORY
COMMENT='Running collector processes';");
db_execute("CREATE TABLE `plugin_hmib_types` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`oid` varchar(40) NOT NULL,
`description` varchar(30) NOT NULL,
PRIMARY KEY (`oid`),
INDEX `id`(`id`))
ENGINE=MyISAM
COMMENT='OID Types for the Host MIB Resources';");
db_execute("CREATE TABLE `plugin_hmib_hrSystemTypes` (
`id` INT(10) unsigned NOT NULL AUTO_INCREMENT,
`sysObjectID` VARCHAR(100) NOT NULL,
`sysDescrMatch` VARCHAR(100) NOT NULL,
`name` VARCHAR(40) NOT NULL,
`version` VARCHAR(10) NOT NULL,
PRIMARY KEY (`sysObjectID`, `sysDescrMatch`),
INDEX `name`(`name`),
INDEX `id`(`id`))
ENGINE = MyISAM
COMMENT='Maps OS Names and Versions to Object ID';");
db_execute("CREATE TABLE `plugin_hmib_hrSWRun_ignore` (
`name` varchar(64) NOT NULL,
`enabled` char(2) NOT NULL default '',
`notes` varchar(255) NOT NULL default '',
PRIMARY KEY (`name`))
ENGINE=MyISAM
COMMENT='The process names that we are interested in tracking at the host level';");
db_execute("INSERT INTO `plugin_hmib_hrSystemTypes` VALUES
(1,'.1.3.6.1.4.1.311.1.1.3.1.1', 'Version 6.1','Windows 7','7'),
(2,'.1.3.6.1.4.1.311.1.1.3.1.2', 'Version 6.1','Windows 2008 Server','2008'),
(3,'.1.3.6.1.4.1.311.1.1.3.1.3', 'Version 6.1','Windows 2008 Domain Contr','2008'),
(4,'.1.3', 'Linux NAS%armv5tejl','DNS-321',''),
(5,'.1.3.6.1.4.1.2.3.1.2.1.1.3', 'IBM%AIX%05.03','AIX','5.3'),
(6,'.1.3.6.1.4.1.8072.3.2.10', 'Linux%2.6.16.21-0.8%','SUSE','10.2'),
(7,'.1.3.6.1.4.1.311.1.1.3.1.1', 'EM64T%Windows Version 5.2','Windows XP x64','5.2'),
(8,'.1.3.6.1.4.1.311.1.1.3.1.1', 'Windows 2000 Version 5.0','Windows 2000','5.0'),
(9,'.1.3.6.1.4.1.311.1.1.3.1.1', 'Windows 2000 Version 5.1','Windows XP','5.1'),
(10,'.1.3.6.1.4.1.8072.3.2.10', 'Linux%2.6.16.60','SUSE','9.0'),
(11,'.1.3.6.1.4.1.311.1.1.3.1.2', 'Windows 2000 Version 5.0','Windows 2000 Server','2000'),
(12,'.1.3.6.1.4.1.311.1.1.3.1.2', 'Windows 2000 Version 5.1','Windows 2000 Server','2000'),
(13,'.1.3.6.1.4.1.311.1.1.3.1.3', 'Windows Version 5.2','Windows 2003 DC','2003'),
(14,'.1.3.6.1.4.1.311.1.1.3.1.2', 'Windows Version 5.2','Windows 2003 Server','2003'),
(16,'.1.3.6.1.4.1.311.1.1.3.1.2', 'Windows Version 6.2','Windows 2012 Server','2012'),
(17,'.1.3.6.1.4.1.311.1.1.3.1.2', 'Windows Version 6.3','Windows 2016 Server','2016'),
(18,'.1.3.6.1.4.1.8072.3.2.10', 'Linux','Linux','Linux'),
(19,'.1.3.6.1.4.1.8072.3.2.10', 'Linux%gentoo%','Gentoo Linux','Gentoo'),
(20,'.1.3.6.1.4.1.8072.3.2.10', 'Linux%ubuntu%','Ubuntu','ubuntu'),
(21,'.1.3.6.1.4.1.8072.3.2.10', 'Linux%centos%','CentOS','CentOS'),
(22,'.1.3.6.1.4.1.8072.3.2.10', 'Linux%ndlp%','McAfee Network DLP','DLP'),
(23,'.1.3', 'Linux%PAE%','Cisco UCM or CCX','UCM'),
(24,'.1.3', 'Identity Services Engine','Cisco ISE','ISE'),
(25,'.1.3', 'Cisco Prime Infrastructure','Cisco Prime Infrastructure','Prime'),
(26,'.1.3', 'AsyncOS','Cisco Web Security Appliance','WSA'),
(27,'.1.3', 'UCOS','Cisco Unity','CUC'),
(28,'.1.3.6.1.4.1.2.3.1.2.1.1.3', 'IBM%AIX%06.01%','AIX','6.1'),
(29,'', 'VMware ESXi','VMware ESXi','ESXi');");
db_execute("INSERT INTO `plugin_hmib_types` VALUES
(1,'.1.3.6.1.2.1.25.3.1.12','Co-Processor'),
(2,'.1.3.6.1.2.1.25.3.1.11','Audio'),
(3,'.1.3.6.1.2.1.25.3.1.10','Video'),
(4,'.1.3.6.1.2.1.25.3.1.2','Unknown'),
(5,'.1.3.6.1.2.1.25.3.1.1','Other'),
(6,'.1.3.6.1.2.1.25.3.1.13','Keyboard'),
(7,'.1.3.6.1.2.1.25.3.1.3','Processor'),
(8,'.1.3.6.1.2.1.25.3.1.4','Network'),
(9,'.1.3.6.1.2.1.25.3.1.5','Printer'),
(10,'.1.3.6.1.2.1.25.3.1.6','Disk'),
(11,'.1.3.6.1.2.1.25.2.1.1','Other Storage'),
(12,'.1.3.6.1.2.1.25.2.1.2','Ram Memory'),
(13,'.1.3.6.1.2.1.25.2.1.3','Virtual Memory'),
(14,'.1.3.6.1.2.1.25.2.1.4','Fixed Disk'),
(15,'.1.3.6.1.2.1.25.2.1.5','Removable Disk'),
(16,'.1.3.6.1.2.1.25.2.1.6','Floppy Disk'),
(17,'.1.3.6.1.2.1.25.2.1.7','Compact Disk'),
(18,'.1.3.6.1.2.1.25.2.1.8','Ram Disk'),
(19,'.1.3.6.1.2.1.25.2.1.9','Flash Memory'),
(20,'.1.3.6.1.2.1.25.2.1.10','Network Disk'),
(21,'.1.3.6.1.2.1.25.3.1.14','Modem'),
(22,'.1.3.6.1.2.1.25.3.1.18','Tape'),
(23,'.1.3.6.1.2.1.25.3.1.15','Parllel Port'),
(24,'.1.3.6.1.2.1.25.3.1.16','Pointing'),
(25,'.1.3.6.1.2.1.25.3.1.17','Serial Port'),
(26,'.1.3.6.1.2.1.25.3.1.19','Clock'),
(27,'.1.3.6.1.2.1.25.3.1.20','Volatile Memory'),
(28,'.1.3.6.1.2.1.25.3.1.21','Non Volatile Memory'),
(29,'.1.3.6.1.2.1.25.3.9.1','Other'),
(30,'.1.3.6.1.2.1.25.3.9.2','Unknown'),
(31,'.1.3.6.1.2.1.25.3.9.3','BerkleyFS'),
(32,'.1.3.6.1.2.1.25.3.9.4','Sys5FS'),
(33,'.1.3.6.1.2.1.25.3.9.6','HPFS'),
(34,'.1.3.6.1.2.1.25.3.9.7','HFS'),
(35,'.1.3.6.1.2.1.25.3.9.8','MFS'),
(36,'.1.3.6.1.2.1.25.3.9.10','VNode'),
(37,'.1.3.6.1.2.1.25.3.9.11','Journaled'),
(38,'.1.3.6.1.2.1.25.3.9.12','iso9660'),
(39,'.1.3.6.1.2.1.25.3.9.13','RockRidge'),
(40,'.1.3.6.1.2.1.25.3.9.14','NFS'),
(41,'.1.3.6.1.2.1.25.3.9.15','Netware'),
(42,'.1.3.6.1.2.1.25.3.9.16','AFS'),
(43,'.1.3.6.1.2.1.25.3.9.17','DFS'),
(44,'.1.3.6.1.2.1.25.3.9.18','AppleShare'),
(45,'.1.3.6.1.2.1.25.3.9.19','RFS'),
(46,'.1.3.6.1.2.1.25.3.9.20','DGCFS'),
(47,'.1.3.6.1.2.1.25.3.9.21','BFS'),
(48,'.1.3.6.1.2.1.25.3.9.22','FAT32'),
(49,'.1.3.6.1.2.1.25.3.9.23','Ext2'),
(50,'.1.3.6.1.2.1.25.3.9.5','FAT'),
(51,'.1.3.6.1.2.1.25.3.9.9','NTFS')");
// optimizations
if (!db_index_exists('data_input_data', 'data_template_data_id')) {
db_execute('ALTER TABLE data_input_data ADD INDEX data_template_data_id(data_template_data_id)');
}
if (!db_index_exists('data_input_data', 'data_input_field_id')) {
db_execute('ALTER TABLE data_input_data ADD INDEX data_input_field_id(data_input_field_id)');
}
if (!db_index_exists('snmp_query_graph', 'graph_template_id')) {
db_execute('ALTER TABLE snmp_query_graph ADD INDEX graph_template_id(graph_template_id)');
}
if (!db_index_exists('snmp_query_graph', 'snmp_query_id')) {
db_execute('ALTER TABLE snmp_query_graph ADD INDEX snmp_query_id(snmp_query_id)');
}
}
/**
* Poller_bottom hook: launches the main Host MIB poller process
* (poller_hmib.php -M) as a background process at the end of each
* Cacti polling cycle. Called by Cacti's poller via the
* 'poller_bottom' hook.
*
* @return void
*
* @global array $config Cacti global configuration array; used to
* locate the PHP binary and this plugin's poller
* script.
*/
function hmib_poller_bottom(): void {
global $config;
include_once($config['base_path'] . '/lib/poller.php');
exec_background(read_config_option('path_php_binary'), ' -q ' . $config['base_path'] . '/plugins/hmib/poller_hmib.php -M');
}
/**
* Config_settings hook: registers this plugin's 'Host MIB' settings tab
* and all of its configuration fields (poller enable/autodiscovery/
* autopurge toggles, row-count/top-N display defaults, concurrency
* limit, and per-table collection frequencies). Called by Cacti's
* settings framework via the 'config_settings' hook.
*
* @return void
*
* @global array $tabs Cacti's settings tabs registry;
* appended with this plugin's tab.
* @global array $settings Cacti's settings fields registry;
* appended with this plugin's fields.
* @global array $hmib_frequencies Map of frequency (seconds) => display
* label, used as the option list for
* the frequency drop-downs.
* @global array $item_rows Cacti's standard row-count option
* list, used for the default row-count
* setting.
*/
function hmib_config_settings(): void {
global $tabs, $settings, $hmib_frequencies, $item_rows;
$tabs['hmib'] = __('Host MIB', 'hmib');
$settings['hmib'] = [
'hmib_header' => [
'friendly_name' => __('Host MIB General Settings', 'hmib'),
'method' => 'spacer',
],
'hmib_enabled' => [
'friendly_name' => __('Host MIB Poller Enabled', 'hmib'),
'description' => __('Check this box, if you want Host MIB polling to be enabled. Otherwise, the poller will not function.', 'hmib'),
'method' => 'checkbox',
'default' => ''
],
'hmib_autodiscovery' => [
'friendly_name' => __('Automatically Discover Cacti Devices', 'hmib'),
'description' => __('Do you wish to automatically scan for and add devices which support the Host Resource MIB from the Cacti host table?', 'hmib'),
'method' => 'checkbox',
'default' => 'on'
],
'hmib_autopurge' => [
'friendly_name' => __('Automatically Purge Devices', 'hmib'),
'description' => __('Do you wish to automatically purge devices that are removed from the Cacti system?', 'hmib'),
'method' => 'checkbox',
'default' => 'on'
],
'hmib_os_type_rows' => [
'friendly_name' => __('Default Row Count', 'hmib'),
'description' => __('How many rows do you wish to see on the HMIB OS Type by default?', 'hmib'),
'method' => 'drop_array',
'default' => '10',
'array' => $item_rows
],
'hmib_top_types' => [
'friendly_name' => __('Default Top Host Types', 'hmib'),
'description' => __('How many processes do you wish to see on the HMIB Dashboard by default?', 'hmib'),
'method' => 'drop_array',
'default' => '10',
'array' => [
5 => __('%d Types', 5, 'hmib'),
8 => __('%d Types', 8, 'hmib'),
10 => __('%d Types', 10, 'hmib'),
15 => __('%d Types', 15, 'hmib')]
],
'hmib_top_processes' => [
'friendly_name' => __('Default Top Processes', 'hmib'),
'description' => __('How many processes do you wish to see on the HMIB Dashboard by default?', 'hmib'),
'method' => 'drop_array',
'default' => '10',
'array' => [
5 => __('%d Processes', 5, 'hmib'),
10 => __('%d Processes', 10, 'hmib'),
20 => __('%d Processes', 20, 'hmib'),
30 => __('%d Processes', 30, 'hmib')]
],
'hmib_concurrent_processes' => [
'friendly_name' => __('Maximum Concurrent Collectors', 'hmib'),
'description' => __('What is the maximum number of concurrent collector process that you want to run at one time?', 'hmib'),
'method' => 'drop_array',
'default' => '10',
'array' => [
1 => __('%d Process', 1, 'hmib'),
2 => __('%d Processes', 2, 'hmib'),
3 => __('%d Processes', 3, 'hmib'),
4 => __('%d Processes', 4, 'hmib'),
5 => __('%d Processes', 5, 'hmib'),
10 => __('%d Processes', 10, 'hmib'),
20 => __('%d Processes', 20, 'hmib'),
30 => __('%d Processes', 30, 'hmib'),
40 => __('%d Processes', 40, 'hmib'),
50 => __('%d Processes', 50, 'hmib')]
],
'hmib_autodiscovery_header' => [
'friendly_name' => __('Host Auto Discovery Frequency', 'hmib'),
'method' => 'spacer',
],
'hmib_autodiscovery_freq' => [
'friendly_name' => __('Auto Discovery Frequency', 'hmib'),
'description' => __('How often do you want to look for new Cacti Devices?', 'hmib'),
'method' => 'drop_array',
'default' => '300',
'array' => $hmib_frequencies
],
'hmib_automation_header' => [
'friendly_name' => __('Host Graph Automation', 'hmib'),
'method' => 'spacer',
],
'hmib_automation_frequency' => [
'friendly_name' => __('Automatically Add New Graphs', 'hmib'),
'description' => __('How often do you want to check for new objects to graph?', 'hmib'),
'method' => 'drop_array',
'default' => '0',
'array' => [
0 => __('Never', 'hmib'),
1 => __('%d Hour', 1, 'hmib'),
12 => __('%d Hours', 12, 'hmib'),
24 => __('%d Day', 1, 'hmib'),
48 => __('%d Days', 2, 'hmib')]
],
'hmib_frequencies' => [
'friendly_name' => __('Host MIB Table Collection Frequencies', 'hmib'),
'method' => 'spacer',
],
'hmib_hrSWRun_freq' => [
'friendly_name' => __('Running Programs Frequency', 'hmib'),
'description' => __('How often do you want to scan running software?', 'hmib'),
'method' => 'drop_array',
'default' => '300',
'array' => $hmib_frequencies
],
'hmib_hrSWRunPerf_freq' => [
'friendly_name' => __('Running Programs CPU/Memory Frequency', 'hmib'),
'description' => __('How often do you want to scan running software for performance data?', 'hmib'),
'method' => 'drop_array',
'default' => '300',
'array' => $hmib_frequencies
],
'hmib_hrSWInstalled_freq' => [
'friendly_name' => __('Installed Software Frequency', 'hmib'),
'description' => __('How often do you want to scan for installed software?', 'hmib'),
'method' => 'drop_array',
'default' => '86400',
'array' => $hmib_frequencies
],
'hmib_hrStorage_freq' => [
'friendly_name' => __('Storage Frequency', 'hmib'),
'description' => __('How often do you want to scan for Storage performance data?', 'hmib'),
'method' => 'drop_array',
'default' => '3600',
'array' => $hmib_frequencies
],
'hmib_hrDevices_freq' => [
'friendly_name' => __('Device Frequency', 'hmib'),
'description' => __('How often do you want to scan for Device performance data?', 'hmib'),
'method' => 'drop_array',
'default' => '3600',
'array' => $hmib_frequencies
],
'hmib_hrProcessor_freq' => [
'friendly_name' => __('Processor Frequency', 'hmib'),
'description' => __('How often do you want to scan for Processor performance data?', 'hmib'),
'method' => 'drop_array',
'default' => '300',
'array' => $hmib_frequencies
]
];
}
/**
* Config_arrays hook: initializes the plugin's collection-frequency
* option list and the SNMP OID tree maps (hrSystem, hrSWRun,
* hrSWRunPerf, hrSWInstalled, hrStorage, hrDevices, hrProcessor) used
* by the poller collectors, surfaces any pending session message,
* registers the OS Types management menu entry and user-realm role
* augmentations, and triggers a schema/hooks upgrade check. Called by
* Cacti's plugin framework via the 'config_arrays' hook on every page
* load.
*
* @return void
*
* @global array $menu Cacti's admin menu registry;
* appended with this plugin's OS Types
* entry.
* @global array $messages Cacti's session-message display
* registry.
* @global array $hmib_frequencies Populated here with the map of
* frequency (seconds) => display label.
* @global array $hrSystem Populated here with the hrSystem SNMP
* OID tree map.
* @global array $hrSWRun Populated here with the hrSWRun SNMP
* OID tree map.
* @global array $hrSWRunPerf Populated here with the hrSWRunPerf
* SNMP OID tree map.
* @global array $hrSWInstalled Populated here with the hrSWInstalled
* SNMP OID tree map.
* @global array $hrStorage Populated here with the hrStorage SNMP
* OID tree map.
* @global array $hrDevices Populated here with the hrDevices SNMP
* OID tree map.
* @global array $hrProcessor Populated here with the hrProcessor
* SNMP OID tree map.
*/
function hmib_config_arrays(): void {
global $menu, $messages, $hmib_frequencies;
global $hrSystem, $hrSWRun, $hrSWRunPerf, $hrSWInstalled, $hrStorage, $hrDevices, $hrProcessor;
$hmib_frequencies = [
-1 => __('Disabled', 'hmib'),
60 => __('%d Minute', 1, 'hmib'),
300 => __('%d Minutes', 5, 'hmib'),
600 => __('%d Minutes', 10, 'hmib'),
1200 => __('%d Minutes', 20, 'hmib'),
3600 => __('%d Hour', 1, 'hmib'),
7200 => __('%d Hours', 2, 'hmib'),
14400 => __('%d Hours', 4, 'hmib'),
43200 => __('%d Hours', 12, 'hmib'),
86400 => __('%d Day', 1, 'hmib')
];
$hrSystem = [
'baseOID' => '.1.3.6.1.2.1.25.1.',
'uptime' => '.1.3.6.1.2.1.25.1.1.0',
'date' => '.1.3.6.1.2.1.25.1.2.0',
'initLoadDevice' => '.1.3.6.1.2.1.25.1.3.0',
'initLoadParams' => '.1.3.6.1.2.1.25.1.4.0',
'users' => '.1.3.6.1.2.1.25.1.5.0',
'processes' => '.1.3.6.1.2.1.25.1.6.0',
'maxProcesses' => '.1.3.6.1.2.1.25.1.7.0',
'memory' => '.1.3.6.1.2.1.25.2.2.0',
'sysDescr' => '.1.3.6.1.2.1.1.1.0',
'sysObjectID' => '.1.3.6.1.2.1.1.2.0',
'sysUptime' => '.1.3.6.1.2.1.1.3.0',
'sysContact' => '.1.3.6.1.2.1.1.4.0',
'sysName' => '.1.3.6.1.2.1.1.5.0',
'sysLocation' => '.1.3.6.1.2.1.1.6.0'
];
$hrSWRun = [
'baseOID' => '.1.3.6.1.2.1.25.4.2.1',
'index' => '.1.3.6.1.2.1.25.4.2.1.1',
'name' => '.1.3.6.1.2.1.25.4.2.1.2',
'path' => '.1.3.6.1.2.1.25.4.2.1.4',
'parameters' => '.1.3.6.1.2.1.25.4.2.1.5',
'type' => '.1.3.6.1.2.1.25.4.2.1.6',
'status' => '.1.3.6.1.2.1.25.4.2.1.7'
];
$hrSWRunPerf = [
'baseOID' => '.1.3.6.1.2.1.25.5.1.1',
'perfCPU' => '.1.3.6.1.2.1.25.5.1.1.1',
'perfMemory' => '.1.3.6.1.2.1.25.5.1.1.2'
];
$hrSWInstalled = [
'baseOID' => '.1.3.6.1.2.1.25.6.3.1',
'index' => '.1.3.6.1.2.1.25.6.3.1.1',
'name' => '.1.3.6.1.2.1.25.6.3.1.2',
'type' => '.1.3.6.1.2.1.25.6.3.1.4',
'date' => '.1.3.6.1.2.1.25.6.3.1.5'
];
$hrStorage = [
'baseOID' => '.1.3.6.1.2.1.25.2.3',
'index' => '.1.3.6.1.2.1.25.2.3.1.1',
'type' => '.1.3.6.1.2.1.25.2.3.1.2',
'description' => '.1.3.6.1.2.1.25.2.3.1.3',
'allocationUnits' => '.1.3.6.1.2.1.25.2.3.1.4',
'size' => '.1.3.6.1.2.1.25.2.3.1.5',
'used' => '.1.3.6.1.2.1.25.2.3.1.6',
'failures' => '.1.3.6.1.2.1.25.2.3.1.7'
];
$hrDevices = [
'baseOID' => '.1.3.6.1.2.1.25.3.2.1',
'index' => '.1.3.6.1.2.1.25.3.2.1.1',
'type' => '.1.3.6.1.2.1.25.3.2.1.2',
'description' => '.1.3.6.1.2.1.25.3.2.1.3',
'status' => '.1.3.6.1.2.1.25.3.2.1.5',
'errors' => '.1.3.6.1.2.1.25.3.2.1.6',
];
$hrProcessor = [
'baseOID' => '.1.3.6.1.2.1.25.3.3.1',
'load' => '.1.3.6.1.2.1.25.3.3.1.2'
];
if (isset($_SESSION['hmib_message']) && $_SESSION['hmib_message'] != '') {
$messages['hmib_message'] = ['message' => $_SESSION['hmib_message'], 'type' => 'info'];
}
$menu[__('Management')]['plugins/hmib/hmib_types.php'] = __('OS Types', 'hmib');
if (function_exists('auth_augment_roles')) {
auth_augment_roles(__('Normal User'), ['hmib.php']);
auth_augment_roles(__('General Administration'), ['hmib_types.php']);
}
hmib_check_upgrade();
}
/**
* Draw_navigation_text hook: registers the breadcrumb/navigation title
* entries for this plugin's hmib.php and hmib_types.php pages and their
* sub-views. Called by Cacti's navigation framework via the
* 'draw_navigation_text' hook.
*
* @param array $nav The navigation entries array being built up.
*
* @return array The $nav array with this plugin's entries added.
*/
function hmib_draw_navigation_text($nav): array {
$nav['hmib.php:summary'] = ['title' => __('Host MIB Inventory Summary', 'hmib'), 'mapping' => '', 'url' => 'hmib.php', 'level' => '0'];
$nav['hmib.php:devices'] = ['title' => __('Host MIB Details', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
$nav['hmib.php:storage'] = ['title' => __('Host MIB Storage', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
$nav['hmib.php:hardware'] = ['title' => __('Host MIB Hardware', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
$nav['hmib.php:running'] = ['title' => __('Host MIB Running Processes', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
$nav['hmib.php:history'] = ['title' => __('Host MIB Process Use History', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
$nav['hmib.php:software'] = ['title' => __('Host MIB Software Inventory', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
$nav['hmib.php:graphs'] = ['title' => __('Host MIB Graphs', 'hmib'), 'mapping' => '', 'url' => '', 'level' => '0'];
$nav['hmib_types.php:'] = ['title' => __('Host MIB OS Types', 'hmib'), 'mapping' => 'index.php:', 'url' => 'hmib_types.php', 'level' => '1'];
$nav['hmib_types.php:actions'] = ['title' => __('Actions', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2'];
$nav['hmib_types.php:edit'] = ['title' => __('(Edit)', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2'];
$nav['hmib_types.php:import'] = ['title' => __('Import', 'hmib'), 'mapping' => 'index.php:,hmib_types.php:', 'url' => 'hmib_types.php', 'level' => '2'];
return $nav;
}
/**
* Top_header_tabs/top_graph_header_tabs hook: prints the Host MIB tab
* icon/link in Cacti's page header, using the 'down' (active) icon when
* currently viewing hmib.php. Called by Cacti's header rendering via
* the 'top_header_tabs'/'top_graph_header_tabs' hooks.
*
* @return void
*
* @global array $config Cacti global configuration array; used to
* build the tab's URL and image paths.
*/
function hmib_show_tab(): void {
global $config;
if (api_user_realm_auth('hmib.php')) {
if (substr_count($_SERVER['REQUEST_URI'], 'hmib.php')) {
print '<a href="' . $config['url_path'] . 'plugins/hmib/hmib.php"><img src="' . $config['url_path'] . 'plugins/hmib/images/tab_hmib_down.gif" alt="hmib"></a>';
} else {
print '<a href="' . $config['url_path'] . 'plugins/hmib/hmib.php"><img src="' . $config['url_path'] . 'plugins/hmib/images/tab_hmib.gif" alt="hmib"></a>';
}
}
}
/**
* Data-provider hook returning a device's processor load value(s) for
* use by Cacti's script server, either a single processor's load (by
* index) or the average load across all processors (index 4000).
* Called via the 'hmib_get_cpu' hook from script-server-backed data
* queries/graph templates.
*
* @param array $host_index The script-server argument array containing
* 'host_id' and 'index'.
*
* @return array|string The unmodified $host_index array when not
* called by the script server or when the table
* doesn't exist, otherwise the CPU load value (or
* '0' if none found).
*
* @global bool $called_by_script_server Whether this call originated
* from Cacti's script server;
* when false, $host_index is
* returned unmodified.
*/
function hmib_get_cpu(array $host_index): array|string {
global $called_by_script_server;
if (!db_table_exists('plugin_hmib_hrProcessor')) {
return $host_index;
}
$host_id = $host_index['host_id'];
$index = $host_index['index'];
if (!$called_by_script_server) {
return $host_index;
} else {
if ($index != 4000) {
$value = db_fetch_cell("SELECT `load`
FROM plugin_hmib_hrProcessor
WHERE host_id=$host_id
ORDER BY `index`
LIMIT $index,1");
} else {
$value = db_fetch_cell("SELECT AVG(`load`)
FROM plugin_hmib_hrProcessor
WHERE host_id=$host_id
ORDER BY `index`");
}
if (empty($value)) {
return '0';
} else {
return $value;
}
}
}
/**
* Data-provider hook returning the list of available processor indexes
* for a device, plus a synthetic 'Total' (index 4000) entry for the
* average-load option, for use by Cacti's script server when building
* data query index selection lists. Called via the
* 'hmib_get_cpu_indexes' hook.
*
* @param array $host_index The script-server argument array containing
* 'host_id'.
*
* @return array|mixed The unmodified $host_index argument when the
* plugin_hmib_hrProcessor table doesn't exist,
* otherwise an array of available processor
* indexes plus the 'Total' entry.
*
* @global bool $called_by_script_server Reserved/declared for parity
* with hmib_get_cpu(); not used
* directly here.
*/
function hmib_get_cpu_indexes(array $host_index) {
global $called_by_script_server;
if (!db_table_exists('plugin_hmib_hrProcessor')) {
return $host_index;
}
$host_id = $host_index['host_id'];
$rarray = [];
$indexes = db_fetch_assoc("SELECT `index`
FROM plugin_hmib_hrProcessor
WHERE host_id=$host_id
ORDER BY `index`");
if (cacti_sizeof($indexes)) {
$i = 0;
foreach ($indexes as $i) {
$rarray[] = $i;
}
}
$rarray[4000] = 'Total';
return $rarray;
}
/**
* Data-provider hook returning a device's storage size/used value
* (handling signed 32-bit overflow wraparound per the Host Resources
* MIB convention) for use by Cacti's script server. Called via the
* 'hmib_get_disk' hook from script-server-backed data queries/graph
* templates.
*
* @param array $host_index The script-server argument array containing
* 'host_id', 'index', and 'arg' ('total' for
* size, otherwise used space).
*
* @return array|string The unmodified $host_index array when not
* called by the script server or when the table
* doesn't exist, otherwise the requested storage
* value (or '0' if none found).
*
* @global bool $called_by_script_server Whether this call originated
* from Cacti's script server;
* when false, $host_index is
* returned unmodified.
*/
function hmib_get_disk(array $host_index): array|string {
global $called_by_script_server;
if (!db_table_exists('plugin_hmib_hrStorage')) {
return $host_index;
}
$host_id = $host_index['host_id'];
$index = $host_index['index'];
$arg = $host_index['arg'];
if (!$called_by_script_server) {
return $host_index;
} else {
if ($arg == 'total') {
$value = db_fetch_cell("SELECT IF(size >= 0, allocationUnits*size, allocationUnits*(ABS(size)+2147483647)) AS size
FROM plugin_hmib_hrStorage
WHERE host_id=$host_id
AND `index`=$index");
} else {
$value = db_fetch_cell("SELECT IF(used >= 0, allocationUnits*used, allocationUnits*(ABS(used)+2147483647)) AS used
FROM plugin_hmib_hrStorage
WHERE host_id=$host_id
AND `index`=$index");
}
if (empty($value)) {
return '0';
} else {
return $value;
}
}
}