コード例 #1
0
ファイル: mib.inc.php プロジェクト: samyscoub/librenms
 *
 * Author: Paul Gear
 * Copyright (c) 2015 Gear Consulting Pty Ltd <*****@*****.**>
 *
 * 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 3 of the License, or (at your
 * option) any later version.  Please see LICENSE.txt at the top level of
 * the source code distribution for details.
 */
$rrd_list = array();
$prefix = rrd_name($device['hostname'], array($subtype, ''), '');
foreach (glob($prefix . '*.rrd') as $filename) {
    // find out what * expanded to
    $globpart = str_replace($prefix, '', $filename);
    // take off the prefix
    $instance = substr($globpart, 0, -4);
    // take off ".rrd"
    $ds = array();
    $mibparts = explode('-', $subtype);
    $mibvar = end($mibparts);
    $ds['ds'] = name_shorten($mibvar);
    $ds['descr'] = "{$mibvar}-{$instance}";
    $ds['filename'] = $filename;
    $rrd_list[] = $ds;
}
$colours = 'mixed';
$scale_min = '0';
$nototal = 0;
$simple_rrd = true;
require 'includes/graphs/generic_multi_line.inc.php';
コード例 #2
0
ファイル: snmp.inc.php プロジェクト: REAP720801/librenms
function snmp_mib_parse($oid, $mib, $module, $mibdir = null)
{
    global $debug;
    $fulloid = explode(".", $oid);
    $lastpart = end($fulloid);
    $cmd = "snmptranslate -Td -On";
    $cmd .= mibdir($mibdir);
    $cmd .= " -m " . $module . " " . $module . "::";
    $cmd .= $lastpart;
    $result = array();
    $lines = preg_split('/\\n+/', trim(shell_exec($cmd)));
    foreach ($lines as $l) {
        $f = preg_split('/\\s+/', trim($l));
        // first line is all numeric
        if (preg_match('/^[\\d.]+$/', $f[0])) {
            $result['oid'] = $f[0];
            continue;
        }
        // then the name of the object type
        if ($f[1] && $f[1] == "OBJECT-TYPE") {
            $result['object_type'] = $f[0];
            $result['shortname'] = str_replace($mib, '', $f[0]);
            $result['dsname'] = name_shorten($f[0], $mib);
            continue;
        }
        // then the other data elements
        if ($f[0] == "--" && $f[1] == "FROM") {
            $result['module'] = $f[2];
            continue;
        }
        if ($f[0] == "MAX-ACCESS") {
            $result['max_access'] = $f[1];
            continue;
        }
        if ($f[0] == "STATUS") {
            $result[strtolower($f[0])] = $f[1];
            continue;
        }
        if ($f[0] == "SYNTAX") {
            $result[strtolower($f[0])] = $f[1];
            continue;
        }
        if ($f[0] == "DESCRIPTION") {
            $desc = explode('"', $l);
            if ($desc[1]) {
                $str = preg_replace('/^[\\s.]*/', '', $desc[1]);
                $str = preg_replace('/[\\s.]*$/', '', $str);
                $result[strtolower($f[0])] = $str;
            }
            continue;
        }
    }
    // The main mib entry doesn't have any useful data in it - only return items that have the syntax specified.
    if (isset($result['syntax']) && isset($result['object_type'])) {
        $result['mib'] = $mib;
        return $result;
    } else {
        return null;
    }
}