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

File check_snmp_dell_cmc of Package nagios-plugins-snmp

 
1
#!/usr/bin/php
2
<?php
3
// Author: Carsten Schoene
4
// Last change: 2009-07-15 
5
// required arguments
6
// $1 = Host / IP
7
// $2 = read community string
8
$switchType="SNMPv2-SMI::enterprises.674.10892.2.1.1.2.0";
9
10
$grad = iconv("UTF-8","ISO-8859-15","°");
11
define('MYNAME',"check_snmp_dell_cmc");
12
define('OK',0);
13
define('WARNING',1);
14
define('CRITICAL',2);
15
define('UNKNOWN',3);
16
define('DEPENDENT',4);
17
18
define_syslog_variables();
19
openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
20
21
if ( ! extension_loaded("snmp") ) {
22
        if ( ! dl("snmp") ) {
23
                syslog(LOG_ERR,"snmp extension not loaded!");
24
                exit;
25
        }
26
}
27
ini_set("display_errors","on");
28
// get working directory
29
define('BASE',dirname(__FILE__));
30
31
$cmdlineopt = getopt("H:C:");
32
if (empty($cmdlineopt)) {
33
        echo "Usage: " . MYNAME . " -H [<hostname> | <ipaddress>] -C [<community>]\n";
34
        echo "\t -H\t Hostname or IP address (default: localhost)\n";
35
        echo "\t -C\t Community (default: public)\n";
36
        exit(1);
37
}
38
if ( isset($cmdlineopt['H']) ) {
39
    $hostname = $cmdlineopt['H'];
40
} else {
41
    $hostname = "localhost";
42
}
43
44
if ( isset($cmdlineopt['C']) ) {
45
    $community = $cmdlineopt['C'];
46
} else {
47
    $community = "public";
48
}
49
$swTypeline = @snmpget($hostname,$community,$switchType);
50
if ( $swTypeline == FALSE ) {
51
    echo "Can't get switchtype\n";
52
    exit(UNKNOWN);
53
} else {
54
    $swTypearr = explode(": ",$swTypeline);
55
    $swType = trim(ereg_replace("\"","",$swTypearr[1]));
56
}
57
58
switch ($swType) {
59
    case "PowerEdge M1000e":
60
        $cmc['globalState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.1.0";
61
        $cmc['globalState']['label'] = "Global:";
62
        $cmc['ioModuleState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.2.0";
63
        $cmc['ioModuleState']['label'] = "IO:";
64
        $cmc['kvmState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.3.0";
65
        $cmc['kvmState']['label'] = "KVM:";
66
        $cmc['redState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.4.0";
67
        $cmc['redState']['label'] = "RED:";
68
        $cmc['powerState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.5.0";
69
        $cmc['powerState']['label'] = "Power:";
70
        $cmc['fanState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.6.0";
71
        $cmc['fanState']['label'] = "Fan:";
72
        $cmc['bladeState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.7.0";
73
        $cmc['bladeState']['label'] = "Blade:";
74
        $cmc['tempState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.8.0";
75
        $cmc['tempState']['label'] = "Temprature:";
76
        $cmc['cmcState']['oid'] = "SNMPv2-SMI::enterprises.674.10892.2.3.1.9.0";
77
        $cmc['cmcState']['label'] = "CMC:";
78
        define(1,'STATUS_OTHER');
79
        define(2,'STATUS_UNKNOWN');
80
        define(3,'STATUS_OK');
81
        define(4,'STATUS_NONCRITICAL');
82
        define(5,'STATUS_CRITICAL');
83
        define(6,'STATUS_NONRECOVERABLE');
84
85
        foreach ( $cmc as $key => $state ) {
86
            $cmc[$key]['reading'] = @snmpget($hostname,$community,$state['oid']);
87
            $tmp = explode(": ",$cmc[$key]['reading']);
88
            $cmc[$key]['value'] = $tmp[1];
89
            $cmc[$key]['state'] = constant($cmc[$key]['value']);
90
91
        }
92
        $output = "";
93
        foreach ( $cmc as $key => $value ) {
94
            
95
            $output .= $cmc[$key]['label'] . " " . $cmc[$key]['state'] . "    ";
96
        }
97
98
        echo $output;   
99
        if ( ereg('STATUS_NONRECOVERABLE',$output) ) {
100
            exit(CRITICAL);
101
        }
102
        if ( ereg('STATUS_CRITICAL',$output) ) {
103
            exit(CRITICAL);
104
        }
105
        if ( ereg('STATUS_NONCRITICAL',$output) ) {
106
            exit(WARNGING);
107
        }
108
        if ( ereg('STATUS_UNKOWN',$output) ) {
109
            exit(UNKNOWN);
110
        }
111
        if ( ereg('STATUS_OTHER',$output) ) {
112
            exit(UNKNOWN);
113
        }
114
        if ( ereg('STATUS_OK',$output) ) {
115
            exit(OK);
116
        }
117
    break;
118
    default:
119
        echo "CMC-type $swType is currently not supported";
120
}
121
?>
122