본문 바로가기
Monitoring

Cacti (System Monitoring Tool) + intropage 설치 방법

by journes 2019. 3. 6.


Cacti (System Monitoring Tool) + intropage  설치 방법 


리소스모니터링 Tool로 작은 규모의 시스템 또는  전형적인 IDC인프라 관리용으로 사용하기 좋습니다.  최근에는 Docker 환경으로 바뀌면서 모니터링 툴 역시 promethus 나 grafana 등으로

 변경되는 추세이기는 하지만. 아직도 많이 사용되는 툴 입니다.  특히 네트웍모니터링용 (snmp 나 mib 값 활용) 으로 아주 좋습니다.  

   * 네트웍 모니터링 용으만 사용한다면  weaathermap 과 같이 사용하는걸 추천 드립니다.    

 



1) 관련 패키지 설치.


1
2
#yum install  httpd httpd-devel  mysql mysql-server  php-mysql php-pear php-common php-gd php-devel php
 php-mbstring php-cli php-mysql  php-snmp net-snmp-utils p net-snmp-libs php-pear-Net-SMTP rrdtool --skip-broken 

cs



2) repo 추가.


1
2
3
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
 
cs



3) cacti 설치.


1
2
yum install cacti
 
cs



4) mysql 계정생성


1
2
mysqladmin -u root password mypasswd
 
cs


5) DB & user 생성


1
2
3
4
5
6
mysql -u root -p
mysql> create database cacti;
mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'mypasswd';
mysql> FLUSH privileges;
mysql> quit
 

cs



6) cacti table 등록


1
2
mysql -u root -p cacti < /usr/share/doc/cacti-0.8.8b/cacti.sql
 
cs



8) vi /etc/httpd/conf.d/cacti.con 수정



1
2
3
4
5
6
7
Alias /cacti /usr/share/cacti
<directory cacti="" share="" usr="">
Order Deny,Allow
Deny from all
Allow from all
</directory>
 
cs



9) vi /usr/share/cacti/include/config.php


1
2
3
4
5
6
7
8
9
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "mypasswd";
$database_port = "3306";
$database_ssl = false;
 
cs



10) cron 등록


1
2
*/5 * * * *     cacti     /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
cs



11) snmpd.conf 수정


1
2
3
4
5
6
com2sec public 127.0.0.1  localhost
group   MyROGroup  v1     public
group   MyROGroup  v2c     public
view    all     included.1      80
access  public ""    any     noauth  exact   all     none    none
 
cs



/etc/php.ini


1
2
extension_dir = "/usr/lib64/php/modules"
 
cs



/etc/httpd/conf.d/cacti.conf


1
2
3
4
5
6
7
8
9
10
11
12
<Directory /usr/share/cacti/>
        <IfModule mod_authz_core.c>
                # httpd 2.4
                Require host localhost
        </IfModule>
        <IfModule !mod_authz_core.c>
                # httpd 2.2
                Order deny,allow
#               Deny from all
                Allow from all
        </IfModule>
 
cs



12) plugin 설치




> settings


1
2
3
# wget http://docs.cacti.net/_media/plugin:settings-v0.71-1.tgz -O settings.tgz 
# chown -R cacti.root setting
 
cs



> clog


1
2
3
# wget http://docs.cacti.net/_media/plugin:clog-v1.7-1.tgz -O clog.tgz
# chown -R cacti.root clog
 
cs




> monitor


1
2
3
# wget http://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz -O monitor.tgz
# chown -R cacti.root monitor
 
cs



>thold



1
2
3
#http://docs.cacti.net/_media/plugin:thold-v0.5.0.tgz
#chown -R cacti.root thold
 
cs



>realtime


1
2
3
4
#wget http://docs.cacti.net/_media/plugin:realtime-v0.5-2.tgz
#chown -R cacti.root realtime
#mkdir /tmp/cacti-realtime && chown apache:apache /tmp/cacti-realtime
 
cs



>rrdclean


1
2
3
4
# wget http://docs.cacti.net/_media/plugin:rrdclean-v0.41.tgz -O rrdclean-v0.41.tgz
# chown -R cacti.root rrdclean
# mkdir /usr/share/cacti/rra/{backup,archive} && chown cacti:root /usr/share/cacti/rra/{backup,archive}
 
cs




>hmlb


1
2
#wget http://docs.cacti.net/_media/plugin:hmib-v1.4-2.tgz -O - | tar xvzf - -C /usr/share/cacti/plugins/
 
cs



[설정완료 이미지]


>intropage (메인페이지 변경)


1
2
3
4
5
6
7
8
##download link 
 https://forums.cacti.net/download/file.php?id=33296&sid=4e1e3477c8cb39610508eb253ec5adb7

##download link      
https://github.com/mantisbt/mantisbt/blob/master/plugins/MantisGraph/core/graph_api.php

##download link 
https://forums.cacti.net/download/file.php?id=29858&sid=4e1e3477c8cb39610508eb253ec5adb7
#mv setup.php.txt setup.php
 
cs




[ 설정 완료 이미지]


 




## 참고 ## 


> intropage (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
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
<?php
function plugin_intropage_install ()     {
    api_plugin_register_hook('intropage''console_after''display_information''setup.php');
}
function plugin_intropage_uninstall ()     {
}
function plugin_intropage_version()     {
    return intropage_version();
}
 
function intropage_version () {
    return array(     'name'          => 'intropage',
               'version'      => '0.4',
               'longname'     => 'Intropage',
               'author'     => 'Petr Macek',
               'homepage'     => 'http://www.kostax.cz/cacti',
               'email'     => 'petr.macek@kostax.cz',
               'url'          => 'http://www.kostax.cz/cacti/checkforupdates/'
          );
}
function plugin_intropage_check_config () {
     return true;
}
function display_information ()     {
    global $input_types$poller_options$config;
    $gd = function_exists ("imagecreatetruecolor") ? true:false;
    $logfile = read_config_option("path_cactilog");
    $lines = 1000;
    $time_url = "http://www.unixtimestamp.com/index.php";
?>
<script type="text/javascript">
function hide_display (id)     {
    var temp = document.getElementById(id);
    if (temp.style.display=='block')
     temp.style.display='none';
    else
     temp.style.display='block';
    return false;
}
</script>
<?php
    // ---------- Hosts
    echo "\n\n<table>\n";
    echo "<tr><td style=\"font-size: 12px; vertical-align: top; padding-right: 5em;\">\n";
    $all  = db_fetch_cell ("select count(id) from host");
    $live = db_fetch_cell ("select count(id) from host where status='3' and disabled=''");
    $down = db_fetch_cell ("select count(id) from host where status='1' and disabled=''");
    $reco = db_fetch_cell ("select count(id) from host where status='2' and disabled=''");
    $disa = db_fetch_cell ("select count(id) from host where disabled='on'");
    if ($down > 0)     {
     $alarm = "red";
    }
    else if ($reco > 0 || $disa > 0)     {
     $alarm = "yellow";
    }
    else     {
     $alarm = "green";
    }
    echo "<strong>Hosts: </strong>\n";
    echo "<img src=\"" . $config["url_path"] . "plugins/intropage/images/alert_" . $alarm . ".png\" />\n<br/><br/>\n";
    if ($gd)     {
     echo "<img src=\"" . $config['url_path'] . "plugins/intropage/graph_pie.php?x=300&y=130&values[Down]=$down&values[Up]=$live&values[Recovering]=$reco&values[Disabled]=$disa\" /><br/>\n";
        echo "<a href=\"" . htmlspecialchars($config['url_path']) . "host.php\">All ($all)</a>\n | ";
        echo "<a href=\"" . htmlspecialchars($config['url_path']) . "host.php?host_status=-2\">Disabled ($disa)</a> | \n";
        echo "<a href=\"" . htmlspecialchars($config['url_path']) . "host.php?host_status=1\">Down ($down)</a> | \n";
        echo "<a href=\"" . htmlspecialchars($config['url_path']) . "host.php?host_status=2\">Recovering ($reco)</a>\n";
    }
    else     {
     echo "All: \n";
        echo "<a href=\"" . htmlspecialchars($config['url_path']) . "host.php\">$all</a>\n";
     echo "<br/>Disabled: \n";
        echo "<a href=\"" . htmlspecialchars($config['url_path']) . "host.php?host_status=-2\">$disa</a>\n";
        echo "<br/>Down: \n";
        echo "<a href=\"" . htmlspecialchars($config['url_path']) . "host.php?host_status=1\">$down</a>\n";
        echo "<br/>Recovering: ";
        echo "<a href=\"" . htmlspecialchars($config['url_path']) . "host.php?host_status=2\">$reco</a>\n";
    }
    echo "</td>\n<td style=\"vertical-align: top; font-size: 12px; padding-right: 5em;\">\n";
 
    // ---------- Thresholds
    echo "<strong>Thresholds: </strong>\n";
    if (db_fetch_cell("SELECT directory FROM plugin_config where directory='thold' and status=1"))     {
     $sql  = "SELECT count(*) FROM thold_data ";
     $sql .= "LEFT JOIN user_auth_perms ON ";
     $sql .= "((thold_data.graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.host_id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.graph_template=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=1)) ";
     $sql .= "WHERE ((user_auth_perms.type != 1 OR user_auth_perms.type is null) AND ((user_auth_perms.type != 3) OR ";
     $sql .= "(user_auth_perms.type is null)) AND ((user_auth_perms.type != 4) OR (user_auth_perms.type is null)))";
     $all = db_fetch_cell ($sql);
     $sql  = "SELECT count(*) FROM thold_data ";
     $sql .= "LEFT JOIN user_auth_perms ON ";
     $sql .= "((thold_data.graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.host_id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.graph_template=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=1)) ";
     $sql .= "WHERE (thold_data.thold_alert!=0 OR thold_data.bl_alert>0) AND ";
     $sql .= "((user_auth_perms.type != 1 OR user_auth_perms.type is null) AND ";
     $sql .= "((user_auth_perms.type != 3) OR (user_auth_perms.type is null)) AND ";
     $sql .= "((user_auth_perms.type != 4) OR (user_auth_perms.type is null)))";
     $brea = db_fetch_cell ($sql);
     $sql  = " SELECT count(*) FROM thold_data ";
     $sql .= "LEFT JOIN user_auth_perms ON ";
     $sql .= "((thold_data.graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.host_id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.graph_template=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=1)) ";
     $sql .= "WHERE ((thold_data.thold_alert!=0 AND ";
     $sql .= "thold_data.thold_fail_count >= thold_data.thold_fail_trigger) OR ";
     $sql .= "(thold_data.bl_alert>0 AND thold_data.bl_fail_count >= thold_data.bl_fail_trigger)) AND ";
     $sql .= "((user_auth_perms.type != 1 OR user_auth_perms.type is null) AND ((user_auth_perms.type != 3) OR ";
     $sql .= "(user_auth_perms.type is null)) AND ((user_auth_perms.type != 4) OR (user_auth_perms.type is null)))";
     $trig = db_fetch_cell ($sql);
     $sql  = "SELECT count(*) FROM thold_data ";
     $sql .= "LEFT JOIN user_auth_perms ON ((thold_data.graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.host_id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.graph_template=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=1)) ";
     $sql .= "WHERE thold_data.thold_enabled='off' AND ((user_auth_perms.type != 1 OR user_auth_perms.type is null) AND ";
        $sql .= "((user_auth_perms.type != 3) OR (user_auth_perms.type is null)) AND ((user_auth_perms.type != 4) OR (user_auth_perms.type is null)))";
     $disa = db_fetch_cell ($sql);
     // all
     $sql  = "SELECT count(*) FROM thold_data ";
     $sql .= "LEFT JOIN user_auth_perms ON ";
     $sql .= "((thold_data.graph_id=user_auth_perms.item_id AND user_auth_perms.type=1 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.host_id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=1) OR ";
     $sql .= "(thold_data.graph_template=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=1)) ";
     $sql .= "WHERE ((user_auth_perms.type != 1 OR user_auth_perms.type is null) AND ((user_auth_perms.type != 3) OR ";
     $sql .= "(user_auth_perms.type is null)) AND ((user_auth_perms.type != 4) OR (user_auth_perms.type is null)))";
     if ($brea > 0 || $trig > 0)     {
         $alarm = "red";
     }
     elseif ($disa > 0)     {
         $alarm = "yellow";
     }
     else     {
         $alarm = "green";
     }
     echo "<img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" />\n<br/><br/>\n";
     if ($gd)     {
         echo "<img src=\"" . $config['url_path'] . "plugins/intropage/graph_pie.php?x=300&y=130&values[Breached]=$brea&values[OK]=" .($all-$brea-$trig-$disa) . "&values[Trigerred]=$trig&values[Disabled]=$disa\" /><br/>\n";
         echo "<a href=\"" . htmlspecialchars($config['url_path']) . "plugins/thold/thold_graph.php?tab=thold&triggered=-1\">All ($all) | </a>\n";
         echo "<a href=\"" . htmlspecialchars($config['url_path']) . "plugins/thold/thold_graph.php?tab=thold&triggered=1\">Breached ($brea) | </a>\n";
         echo "<a href=\"" . htmlspecialchars($config['url_path']) . "plugins/thold/thold_graph.php?tab=thold&triggered=3\">Trigged ($trig) | </a>\n";
         echo "<a href=\"" . htmlspecialchars($config['url_path']) . "plugins/thold/thold_graph.php?tab=thold&triggered=0\">Disabled ($disa)</a>\n";
     }
     else     {
         echo "All: \n";
         echo "<a href=\"" . htmlspecialchars($config['url_path']) . "plugins/thold/thold_graph.php?tab=thold&triggered=-1\">$all</a>\n";
         echo "<br/>Breached: \n";
         echo "<a href=\"" . htmlspecialchars($config['url_path']) . "plugins/thold/thold_graph.php?tab=thold&triggered=1\">$brea</a>\n";
         echo "<br/>Trigged: \n";
         echo "<a href=\"" . htmlspecialchars($config['url_path']) . "plugins/thold/thold_graph.php?tab=thold&triggered=3\">$trig</a>\n";
         echo "<br/>Disabled: \n";
         echo "<a href=\"" . htmlspecialchars($config['url_path']) . "plugins/thold/thold_graph.php?tab=thold&triggered=0\">$disa</a>\n";
     }
    }
    else     {
     echo "Thold plugin not installed/running\n";
    }
    echo "</td>\n<tr><td style=\"vertical-align: top; font-size: 12px; padding-right: 5em;\">\n";
    // ---------- Datasources
    echo "<br/><strong>Data sources: </strong><br/><br/>\n";
    if (!$gd)     {
        echo  "Total: " . db_fetch_cell ("SELECT count(*) FROM data_template_data WHERE local_data_id <> 0") . "<br/>\n";
    }
    $get_val = "";
    $data_count = db_fetch_assoc("SELECT i.type_id, COUNT(i.type_id) AS total FROM data_template_data AS d, data_input AS i WHERE d.data_input_id = i.id AND local_data_id <> 0 GROUP BY i.type_id");
    if (sizeof($data_count)) {
     foreach ($data_count as $item) {
         if (!$gd)     {
          print $input_types[$item["type_id"]] . ": " . $item["total"] . "<br/>\n";
         }
         $get_val .= "&values[" . $input_types[$item["type_id"]] . "]=$item[total]";
     }
    }
    if ($gd)     {
        echo "<img src=\"" . $config['url_path'] . "plugins/intropage/graph_pie.php?x=300&y=130&$get_val\" />\n";
    }
    echo  "</td><td style=\"vertical-align: top; font-size: 12px; padding-right: 5em;\">";
    // ---------- Hosts by templates
    if ($gd)     {
        echo "<br/><strong>Hosts by templates (top 6): </strong><br/><br/>\n";
    }
    else     {
        echo "<br/><strong>Hosts by templates: </strong><br/><br/>\n";
    }
    $sql = "SELECT host_template.id as id, name, count(host.host_template_id) AS pocet FROM host_template LEFT JOIN host ON host_template.id = host.host_template_id GROUP by host_template_id ORDER BY pocet desc";
    $result = db_fetch_assoc ($sql);
    $get_val = "";
    foreach($result as $row)     {
     if (!$gd)     {
          echo $row['name'] . ": <a href=\"" . htmlspecialchars($config['url_path']) . "host.php?host_status=-1&host_template_id=$row[id]\">" . $row['pocet'] . "</a><br/>\n";
     }
     $get_val .= "&values[" . $row['name'] . "]=" . $row['pocet'];
    }
    if ($gd)     {
     echo "<img src=\"" . $config['url_path'] . "plugins/intropage/graph_pie.php?x=400&y=130&$get_val\" />\n</tr>";
    }
    echo "</td></tr>\n";
    echo "</table><br/><br/>\n\n";
    echo "<table>\n";
    // ----------------- time
    echo "<tr>\n<td style=\"vertical-align: top; font-size: 12px;\">\n";
    echo "<strong>Time:</strong></td>";;
    $context = stream_context_create (array ('http'=>array('timeout'=>1)));
    $handle = @fopen ($time_url'r'false$context);
    if ($handle)     {
     while (!feof ($handle))     {
         $line = fread ($handle,256);
         if (preg_match ('/([0-9]{10}) \(UTC\)/',$line$output))     {
          $time = $output[1];
         }
     }
     fclose ($handle);
     $time_local = date("P");
     $diff = $time_local - $time;
     if ($diff < -600 || $diff > 600)     {
         echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_red.png\" /></td>\n";
         echo "<td style=\"font-size: 12px;\">" . date("Y-m-d H:i:s") . " (Please check time. It is different (more than 10 minutes) from http://www.unixtimestamp.com/)</td>\n";
     }
     elseif ($diff < -120 || $diff > 120)     {
         echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_yellow.png\" /></td>\n";
         echo "<td style=\"font-size: 12px;\">" . date("Y-m-d H:i:s") . " (Please check time. It is different (more than 2 minutes) from http://www.unixtimestamp.com/)</td>\n";
     }
     else     {
         echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_green.png\" /></td>\n";
         echo "<td style=\"font-size: 12px;\">" . date("Y-m-d H:i:s") . " (Time on server is equal to http://www.unixtimestamp.com/)</td>\n";
     }
    }
    else     {
         echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_red.png\" /></td>\n";
         echo "<td style=\"font-size: 12px;\"> (I can't check time from $time_url)</td>\n";
    }
    echo "</tr>\n";
    // ----------------- log size
    echo "<tr><td style=\"font-size: 12px;\">\n";
    echo "<strong>Log file size: </strong></td>";
    $size = filesize ($logfile);
    if (!$size)     {
     $alarm = "red"$text = "Log file not accessible";
    }
    else     {
     if ($size < 0)     {
         $alarm = "red";
         $text = "more then 2GB";
     }
     elseif ($size < 255999999)     {
         $alarm = "green";
         $text = humanFileSize($size);
     }
     else     {
         $alarm = "yellow";
         $text = humanFileSize($size) . " (Logfile is quite large)";
     }
    }
    echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" /></td>\n";
    echo "<td style=\"font-size: 12px;\"><a href=\"" . htmlspecialchars($config['url_path']) . "utilities.php?action=view_logfile\">$text</a></td>";
    echo "</tr>\n";
    // ----------------- poller stats
    echo "<tr><td style=\"font-size: 12px;\">\n";
    unset ($time);
    $avg_time = 0;
    $count = 0;
    $text2  = "<tr><td colspan=\"3\">\n";
    $text2 .= "<a href=\"#\" onclick=\"hide_display('log_stats');\">View/hide log</a>\n";
    $text2 .= "<div id=\"log_stats\" style=\"display: none\">";
    $logcontents = tail_file_2 ($logfile$lines);
    echo "<strong>Poller stats (interval " . read_config_option("poller_interval") . "s)</strong></td>\n";
    if (!$size)     {
     $alarm = "red";
     $text = "Log file not accessible";
    }
    else     {
     if (isset ($logcontents['stats']))     {
         foreach ($logcontents['stats'as $item)     {
          $text2 .= "<br/>$item";
          if (strpos ($item"SYSTEM STATS"=== falsecontinue;
          $start = strpos ($item"Time:")+5;
          $end   = strpos ($item" "$start)-1;
          $time  = substr ($item$start$end-$start);
          $count++;
          $avg_time += $time;
         }
         $avg_time = $avg_time/$count;
         $text2 .= "<br/><a href=\"" . htmlspecialchars($config['url_path']) . "utilities.php?action=view_logfile&tail_lines=$lines&message_type=1&reverse=1\">Full log - last $lines lines</a>";
     }
    
     if (!isset ($time))     {
         $alarm = "yellow"$text = "Don't see any Stats, purged log?";
     }
     else {
         $nasobek = read_config_option("poller_interval")/$time;
         if ($nasobek < 1.2)     {
          $alarm = "red"$text = "average " . $avg_time ."s (Polling is almost reaching the limit)";
         }
         else if ($nasobek < 1.5)     {
          $alarm = "yellow"$text = "average " .$avg_time . "s (Polling is close to the limit)";
         }
         else     {
          $alarm = "green"$text = "average " .$avg_time . "s (Polling is finished in time)";
         }
     }
    }
    $text2 .= "</div></td></tr>";
    echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" />\n</td>";
    echo "<td style=\"font-size: 12px;\"> $text</td></tr>\n";
    echo $text2;
 
    // ----------------- errors and warnings
    echo "<tr><td style=\"font-size: 12px;\">\n";
    echo "<strong>Log errors/warnings</strong></td>\n ";
    if (!$size)     {
     $alarm = "red";
     $text = "Log file not accessible";
     $text2 = "";
    }
    else     {
     $alarm = "green"$text = "No errors or warning in log (in last 1000 lines)";
     if ($alarm != "green")     {
         $text2  = "<tr><td colspan=\"3\"><a href=\"#\" onclick=\"hide_display('log_log');\">View/hide log</a>\n";
         $text2 .= "<div id=\"log_log\" style=\"display: none\">";
    
         if (isset ($logcontents['error']))     {
          $alarm = "red"$text = "Errors in log (in last 1000 lines)";
          foreach ( $logcontents['error'as $item)     {
                  $text2 .= "<br/>$item";
              }
         }
         if (isset ($logcontents['warn']))     {
          $alarm = "yellow"$text = "Warnings in log (in last 1000 lines)";
          foreach ($logcontents['warn'as $item)     {
              $text2 .= "<br/>$item";
          }
         }
         $text2 .= "<br/><a href=\"" . htmlspecialchars($config['url_path']) . "utilities.php?tail_lines=$lines&message_type=3&reverse=1&action=view_logfile\">Full log - last $lines lines</a>\n";
         $text2 .= "</div></td></tr>\n";
     }    
    }
    echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" /></td>\n";
    echo "<td style=\"font-size: 12px;\">$text</td></tr>\n";
    echo $text2;
 
    unset ($logcontents);
 
    // ----------------- logins
    echo "<tr><td style=\"font-size: 12px;\">\n";
    echo "<strong>Last 10 logins</strong></td>";
    $user_log_sql = "SELECT user_log.username, user_auth.full_name, user_log.time, user_log.result, user_log.ip FROM user_auth RIGHT JOIN user_log ON user_auth.username = user_log.username ORDER  BY user_log.time desc LIMIT 10";
    $result = db_fetch_assoc ($user_log_sql);
    $text = "Without Failed logins";
    $alarm = "green";
    $text2  = "<tr><td colspan=\"3\">\n";
    $text2 .= "<a href=\"#\" onclick=\"hide_display('log_login');\">View/hide log</a>\n";
    $text2 .= "<div id=\"log_login\" style=\"display: none\">";
    foreach($result as $row)     {
     $text2 .= "<br/>" . $row['time'] . " - " . $row['username'] . "(" . $row['full_name'] .") result: ";
     $text2 .= $row['result'== 0 ? "Failed" : "Success";
     $text2 .= ", IP: " . $row['ip'] . "\n";
     if ($row['result'== 0)     {
         $alarm = "red";
         $text = "Failed logins";
     }
    }
   
    $text2 .= "<br/><a href=\"" . htmlspecialchars($config['url_path']) . "utilities.php?action=view_user_log\">Full log</a>)\n";
    $text2 .= "</div></td></tr>";
    echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" /></td>\n";
    echo "<td style=\"font-size: 12px;\">$text</td></tr>\n";
    echo $text2;
 
// ---------------------- Christopher's value :-)
    // --- same description
    $text2 = "";
    $alarm = "green";
    echo "<tr><td style=\"font-size: 12px;\">\n";
    echo "<strong>Devices with the same description: </strong></td>";
    $query = "SELECT id,description, count(*) FROM host GROUP BY description HAVING count(*)>1";
    $result = db_fetch_assoc ($query);
    $count = sizeof($result);
    if ($count > 0) {
     $alarm = "red";
     $text2 .= "<tr><td colspan=\"3\"><a href=\"#\" onclick=\"hide_display('log_description');\">View/hide log</a>\n";
     $text2 .= "<div id=\"log_description\" style=\"display: none\">";
     foreach ($result as $item) {
         $text2 .= "<br/><a href=\"./host.php?action=edit&id=" . $item['id'] . "\">" . $item['description'] . "</a> " . $item['count'] . "\n";
     }
     $text2 .= "</div></td></tr>";
    }
    echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" /></td>\n";
    echo "<td style=\"font-size: 12px;\">$count</td></tr>\n";
    echo $text2;
 
    // --- x times in tree
    $text2 = "";
    $alarm = "green";
    echo "<tr><td style=\"font-size: 12px;\">\n";
    echo "<strong>Devices in more then one tree: </strong></td>";
    $query = "SELECT description, name, gt.id as idtree FROM graph_tree gt, graph_tree_items gti, host WHERE gt.id=gti.graph_tree_id AND host.id=gti.host_id AND gti.host_id IN (SELECT host_id FROM graph_tree_items GROUP BY host_id HAVING count(*)>1 )";
    $result = db_fetch_assoc ($query);
    $count = sizeof($result);
    if ($count > 0) {
     $alarm = "red";
     $text2 .= "<tr><td colspan=\"3\"><a href=\"#\" onclick=\"hide_display('log_tree');\">View/hide log</a>\n";
     $text2 .= "<div id=\"log_tree\" style=\"display: none\">";
     foreach ($result as $item) {
         $text2 .= "<br/><a href=\"./tree.php?action=edit&id=" . $item['idtree']. "\">" . $item['description'] . "</a>\n";
     }
     $text2 .= "</div></td></tr>";
    }
    echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" /></td>\n";
    echo "<td style=\"font-size: 12px;\">$count</td></tr>\n\n";
    echo $text2;
 
    // --- host without graph
    $text2 = "";
    $alarm = "green";
    echo "<tr><td style=\"font-size: 12px;\">\n";
    echo "<strong>Hosts without graphs: </strong></td>";
    $query = "select id , description FROM host WHERE ID NOT IN (SELEct distinct host_id from graph_local ) AND snmp_version!=0";
    $result = db_fetch_assoc ($query);
    $count = sizeof($result);
    if ($count > 0) {
        $text2 .= "<tr><td colspan=\"3\"><a href=\"#\" onclick=\"hide_display('log_nogr');\">View/hide log</a>\n";
     $text2 .= "<div id=\"log_nogr\" style=\"display: none\">";
     $alarm = "red";
     foreach ($result as $item) {
         $text2 .= "<br/><a href=\"./host.php?action=edit&id=" . $item['id'] . "\">" . $item['description'] . "</a>\n";
     }
     $text2 .= "</div></td></tr>";
    }
    echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" /></td>\n";
    echo "<td style=\"font-size: 12px;\">$count</td></tr>\n";
    echo $text2;
 
    // --- host without tree
    $text2 = "";
    $alarm = "green";
    echo "<tr><td style=\"font-size: 12px;\">\n";
    echo "<strong>Host without tree: </strong></td>";
    $query = "SELECT description, id FROM host WHERE id NOT IN (SELECT host_id AS id FROM graph_tree_items)";
    $result = db_fetch_assoc ($query);
    $count = sizeof($result);
    if ($count > 0) {
     $alarm = "red";
        $text2 .= "<tr><td colspan=\"3\"><a href=\"#\" onclick=\"hide_display('log_notree');\">View/hide log</a>\n";
     $text2 .= "<div id=\"log_notree\" style=\"display: none\">";
 
     foreach ($result as $item) {
         $text2 .= "<br/><a href=\"./host.php?action=edit&id=" . $item['id'] . "\">" . $item['description'] . "</a>\n";
     }
     $text2 .= "</div></td></tr>";
    }
    echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" />\n</td>\n";
    echo "<td style=\"font-size: 12px;\">$count</td></tr>\n";
    echo $text2;
 
    // --- not monitored hosts
    $text2 = "";
    $alarm = "green";
    echo "<tr><td style=\"font-size: 12px;\">\n";
    echo "<strong>Not monitored hosts: </strong></td>";
    if (db_fetch_cell("SHOW COLUMNS FROM `host` LIKE 'monitor'"))     {
        $query = "SELECT description, id FROM host WHERE monitor != 'on'";
     $result = db_fetch_assoc ($query);
     $count = sizeof($result);
     if ($count > 0) {
         $alarm = "red";
             $text2 .= "<tr><td colspan=\"3\"><a href=\"#\" onclick=\"hide_display('log_nomon');\">View/hide log</a>\n";
         $text2 .= "<div id=\"log_nomon\" style=\"display: none\">";
         foreach ($result as $item) {
          $text2 .= "<br/><a href=\"./host.php?action=edit&id=" . $item['id'] . "\">" . $item['description'] . "</a>\n";
         }
         $text2 .= "</div></td></tr>";
     }
     echo "<td><img src=\"" . $config['url_path'] . "plugins/intropage/images/alert_" . $alarm . ".png\" />\n</td>\n";
     echo "<td style=\"font-size: 12px;\">$count</td></tr>\n";
     echo $text2;
    }
    else     {
        echo "<td colspan=\"2\"  style=\"font-size: 12px;\">Monitor not found\n</td></tr>\n";
    }
    echo "</table><br/><br/>\n\n";
    echo "<table>\n";
    // --- Top 5 host with bad ping
    echo "<tr><td style=\"font-size: 12px; padding-right: 5em;\">\n";
    echo "<strong>Top 5 hosts with worst ping response: </strong><br/>";
    $query = "SELECT description, id , avg_time, cur_time FROM host order by avg_time desc limit 5";
    $result = db_fetch_assoc ($query);
    echo "<table><tr><th>Host</th><th>Avg.</th><th>Cur.</th></tr>\n";
    foreach ($result as $item) {
     echo "<tr><td style=\"font-size: 12px; padding-right: 2em;\"><a href=\"./host.php?action=edit&id=" . $item['id'] . "\">" . $item['description'] . "</a></td>\n";
     echo "<td style=\"font-size: 12px; padding-right: 2em; text-align: right;\">" . round ($item['avg_time'],2) . "</td>\n";
     echo "<td style=\"font-size: 12px; padding-right: 2em; text-align: right;\">" . round ($item['cur_time'],2) . "</td></tr>\n";
    }
    echo "</table>\n";
    echo "</td>\n";
 
    // --- Top 5 host with lowest availability
    echo "<td style=\"font-size: 12px; padding-right: 5em;\">\n";
    echo "<strong>Top 5 hosts with lowest availability: </strong><br/>";
    $query = "SELECT description, id , availability FROM host order by availability  limit 5;";
    $result = db_fetch_assoc ($query);
    echo "<table><tr><th>Host</th><th>Availability</th></tr>\n";
    foreach ($result as $item) {
     echo "<tr><td style=\"font-size: 12px; padding-right: 2em;\"><a href=\"./host.php?action=edit&id=" . $item['id'] . "\">" . $item['description'] . "</a></td>\n";
     echo "<td style=\"font-size: 12px; padding-right: 2em; text-align: right;\">" . round (trim($item['availability']),2) . "%</td></tr>\n";
    }
    echo "</table>\n";
    echo "</td></tr>\n";
    echo "</table><br/><br/>\n\n";
    echo "<table>\n";
    // ----------------- OS, poller, ...
    echo "<tr>\n<td style=\"vertical-align: top; font-size: 12px;\"><br/><br/>\n";
    if ((file_exists(read_config_option("path_spine"))) && ((function_exists('is_executable')) && (is_executable(read_config_option("path_spine"))))) {
     $out_array = array();
     exec(read_config_option("path_spine") . " --version"$out_array);
     if (sizeof($out_array> 0) {
         $spine_version = $out_array[0];
     }
    }
    if (file_exists(read_config_option("path_spine")) && $poller_options[read_config_option("poller_type")] == 'spine') {
     $type = $spine_version;
    } else {
     $type = $poller_options[read_config_option("poller_type")];
    }
    echo "<strong>Poller type: </strong><a href=\"" . htmlspecialchars($config['url_path']) . "/settings.php?tab=poller\">$type</a>\n";
    echo "</td></tr>\n";
 
    echo "<tr><td  style=\"vertical-align: top; font-size: 12px;\">\n";
    echo "<strong>Running on:</strong> ";
    if (function_exists("php_uname")) {
        print php_uname();
    }
    else     {
        print PHP_OS;
    }
    echo "</td></tr>\n";
    echo "</table>\n\n";
    if (!$gd)
     echo "<br/><br/>Recommendation: For better intropage view, please install PHP GD library";
}
function humanFileSize($size)     {
    if ($size >= 1073741824) {
      $fileSize = round($size / 1024 / 1024 / 1024,1) . 'GB';
    } elseif ($size >= 1048576) {
        $fileSize = round($size / 1024 / 1024,1) . 'MB';
    } elseif($size >= 1024) {
        $fileSize = round($size / 1024,1) . 'KB';
    } else {
        $fileSize = $size . ' bytes';
    }
    return $fileSize;
}
 
function tail_file_2 ($file_name$number_of_lines$line_size = 256) {
    $file_array = array();
    if (file_exists($file_name&& is_readable($file_name)) {
     $handle = @fopen($file_name"r");
     $linecounter = $number_of_lines;
     $pos = -2;
     $beginning = false;
     $text = array();
     while ($linecounter > 0) {
         $t = " ";
         while ($t != "\n") {
          if(fseek($handle$pos, SEEK_END) == -1) {
              $beginning = true;
              break;
          }
          $t = fgetc($handle);
          $pos --;
         }
         $linecounter --;
         if ($beginning) {
          rewind($handle);
         }
         $text[$number_of_lines-$linecounter-1= fgets($handle);
         if ($beginningbreak;
     }
     fclose ($handle);
        $i = 0;
     $stats = 0;
     $warn = 0;
     $error = 0;
     foreach ($text as $line)     {
            if (substr_count($line"STATS"&& $stats < 10) {
                 $file_array['stats'][$stats= $line;
          $stats++;
         }
            if (substr_count($line"WARN"&& $warn < 10) {
             $file_array['warn'][$warn= $line;
          $warn++;
         }
            if (substr_count($line"ERROR"&& $error < 10) {
             $file_array['error'][$error= $line;
          $error++;
         }
        }
    }
    else     {
     return (NULL);
    }
    return $file_array;
}
?>
 
cs

 



> intropage (graph_pie.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
<?php
 
//    $image = imagecreatetruecolor($_GET['x'], $_GET['y']);
    $image = imagecreatetruecolor(400130);
    $white = imagecolorallocate($image255255255);
    $Cacti = imagecolorallocate($image168168168);
    $black = imagecolorallocate($image000);
    $barvy[0= imagecolorallocate($image2357070); // red
    $barvy[1= imagecolorallocate($image7023570); // green
    $barvy[2= imagecolorallocate($image7070235); // blue
    $barvy[3= imagecolorallocate($image25525570); // yellow
    $barvy[4= imagecolorallocate($image23570235); // magenta
    $barvy[5= imagecolorallocate($image70235235); //cyan
    $barvy[6= imagecolorallocate($image168168168); // grey
    $darvy[0= imagecolorallocate($image1687070); // Dark red
    $darvy[1= imagecolorallocate($image7016870); // Dark green
    $darvy[2= imagecolorallocate($image7070168); // Dark blue
    $darvy[3= imagecolorallocate($image16816870); // Dark yellow
    $darvy[4= imagecolorallocate($image16870168); // magenta
    $darvy[5= imagecolorallocate($image70168168); //cyan
    $darvy[6= imagecolorallocate($image000); //black
    imagefill ($image00$Cacti);
    $sum = 0;
    $_GET['values'= array_slice ($_GET['values'],0,6true);
    foreach ($_GET['values'as $value)          {
     $sum+=$value;
    }
    $start = 100$count = 0;
    foreach ($_GET['values'as $key=>$value)     {
     $part = round(($value/$sum* 360 + $start);
     if ($part > 0 && $start != $part){
     for ($i = 60$i > 50$i--) {
          imagefilledarc($image55$i10050$start$part$darvy[$count], IMG_ARC_PIE);
     }
     //imagefilledarc($image, 55, 50, 100, 50, $start, $part, $barvy[$count], IMG_ARC_PIE);
     }
     imagefilledrectangle($image130,($count*10)+(($count+1)*10),142,($count*10)+($count*10)+24$barvy[$count]);
     imagestring ($image3155,($count*10)+(($count+1)*10),  "$key: $value",$white);
          $start = $part$count++;
     }
     $start = 100$count = 0;  
     foreach ($_GET['values'as $key=>$value)     {
     $part = round(($value/$sum* 360 + $start);
     if ($part > 0 && $start != $part){
     imagefilledarc($image555010050$start$part$barvy[$count], IMG_ARC_PIE);
     }
 
          $start = $part$count++;
         } 
    imagestring ($image310,110,  "Total: $sum",$black);
    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);
?>
 
cs