Logoj0ke.net Open Build Service > Projects > server:monitoring > nagios-plugins-snmp > check_mem_lancom
Sign Up | Log In

File check_mem_lancom of Package nagios-plugins-snmp

 
1
#!/usr/bin/php5
2
<?php
3
/*
4
** Author
5
**  Original author Carsten Schoene (cs@linux-administrator.com)
6
**
7
** Copyright
8
**  Copyright (c) 2007 linux-administrator.com
9
**  All Rights Reserved.
10
*/
11
12
$lancomtotal=".1.3.6.1.4.1.2356.600.3.54.1.47.4";
13
$lancomfree=".1.3.6.1.4.1.2356.600.3.54.1.47.5";
14
15
define('MYNAME',"check_mem_lancom");
16
define_syslog_variables();
17
openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
18
19
if ( ! extension_loaded("snmp") ) {
20
        if ( ! dl("snmp") ) {
21
                syslog(LOG_ERR,"snmp extension not loaded!");
22
                exit;
23
        }
24
}
25
ini_set("display_errors","on");
26
27
$cmdlineopt = getopt("H:C:w:c:h");
28
29
if (empty($cmdlineopt)) {
30
    print_help();
31
}
32
33
function print_help() {
34
        echo "Usage: " . MYNAME . " < -H  HOSTNAME | -C COMMUNITY | -w | -c >\n";
35
        echo "\t -H\t target Hostname to check\n";
36
        echo "\t -C\t community name\n";
37
        echo "\t -w\t warning threshold\n";
38
        echo "\t -c\t critical threshold\n";
39
        echo "\t -h\t this help screen\n";
40
        exit(1);
41
}
42
43
function print_message ( $msg, $retval ) {
44
    echo "$msg\n";
45
    exit($retval);
46
}
47
if ( isset($cmdlineopt['H'])  &&  isset($cmdlineopt['C'])  &&  isset($cmdlineopt['w'])  &&  isset($cmdlineopt['c']) ) {
48
49
    $memtotal = explode(" " , snmpget($cmdlineopt['H'], $cmdlineopt['C'], $lancomtotal ) );
50
    $memfree = explode(" " , snmpget($cmdlineopt['H'], $cmdlineopt['C'], $lancomfree ) );
51
52
53
    
54
    $onepercent = $memtotal[1] / 100;
55
56
    $memused = $memtotal[1] - $memfree[1];
57
        
58
    $percentused = $memused / $onepercent;
59
60
    $percentused = round($percentused,0);
61
62
    if ( $percentused > $cmdlineopt['c'] ) {
63
64
        $message = "MEMORY Critical: " . $memused . " Bytes used / " . $memtotal[1] . " Bytes total";
65
        print_message($message,2);
66
67
    } elseif ( $percentused > $cmdlineopt['w'] ) {
68
69
        $message = "MEMORY Warning: " . $memused . " Bytes used / " . $memtotal[1] . " Bytes total";
70
        print_message($message,1);
71
72
    } else {
73
74
        $message = "MEMORY OK: " . $memused . " Bytes used / " . $memtotal[1] . " Bytes total";
75
        print_message($message,0);
76
77
    }
78
79
} else {
80
    print_help();
81
}
82
?>
83