« Mibble - Free SNMP MIB Browser/Parser 基于Java的跨平台MIB查看浏览库 |
Main
| 版本问题 好累 »
November 18, 2004
mib yourself
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。
https://windtear.net/archives/2004/11/18/000379.html
of course it's a MASKed version (some section)
-----> deploy.sh # judge snmpd installed if ! rpm -q net-snmp >/dev/null && ! rpm -q ucd-snmp >/dev/null && ! which snmpd >/dev/null then echo "please install net-snmp(ucd-snmp) first" echo " apt-get install net-snmp" exit fi
if ! grep -q "^pass.*15435.*hostStatic$" /etc/snmp/snmpd.conf; then cat >> /etc/snmp/snmpd.conf << EOF pass .1.3.6.1.4.1.15435.1 /usr/bin/perl /opt/mibscript/hostStatic EOF
-----> hostStatic #!/usr/bin/perl # # Copyright (c) 2004 Zhang Xiuling <windtear@ipcn.org> #
my ($req,$place,$returnOID,$mode);
$place=".1.3.6.1.4.1.15435.1";
main();
sub main { my ($mode,$req); if (scalar(@ARGV) == 2) { ($mode,$req) = @ARGV; } else { ($req) = @ARGV; }
# mode start SWITCH: for ($mode) { /-s/ && exit; /-n/ && do { SWITCH: for ($req) { /$place$/ && do { $returnOID = "$place.1"; last SWITCH; }; /$place\.(.*)$/ && do { if ($1 < 3) { $returnOID = "$place." . ($1 + 1); } else { exit; } last SWITCH; }; exit; } last SWITCH; }; SWITCH: for ($req) { /$place$/ && exit; $returnOID = $req; } } # mode end
print "$returnOID\n"; $_ = $returnOID; SWITCH: {
/^$place\.1$/ && do { print "string\n", getHostname() ; last SWITCH; };
/^$place\.2$/ && do { print "INTEGER\n", numTcpConnAll() ; last SWITCH; };
/^$place\.3$/ && do { print "INTEGER\n", numTcpConnEst() ; last SWITCH; }; } }
sub getHostname { return `/bin/hostname --fqdn`; }
sub numTcpConnAll { return `/bin/netstat -na | grep ^tcp | grep -c -v LISTEN`; }
sub numTcpConnEst { return `/bin/netstat -na | grep -c ESTABLISHED`; }
-----> cat /usr/share/snmp/mibs/IPCN-MIB.txt IPCN-MIB DEFINITIONS ::= BEGIN
IMPORTS OBJECT-TYPE, MODULE-IDENTITY, Counter32, Integer32, Opaque, enterprises, Counter64 FROM SNMPv2-SMI
TEXTUAL-CONVENTION, DisplayString, TruthValue FROM SNMPv2-TC;
ipcn MODULE-IDENTITY LAST-UPDATED "0411180000Z" ORGANIZATION "IPCN" CONTACT-INFO "Primary Author: Zhang Xiuling email: windtear@ipcn.org" DESCRIPTION "This file defines the private UCD SNMP MIB extensions." REVISION "0411180000Z" DESCRIPTION "SMIv2 version" ::= { enterprises 15435 }
hostStatic OBJECT IDENTIFIER ::= { ipcn 1 }
hostname OBJECT-TYPE SYNTAX DisplayString MAX-ACCESS read-only STATUS current DESCRIPTION "The process name we're counting/checking on." ::= { hostStatic 1 }
numTcpConn OBJECT-TYPE SYNTAX Integer32 MAX-ACCESS read-only STATUS current DESCRIPTION "Numbers of TCP connections." ::= { hostStatic 2 }
numTcpConnEst OBJECT-TYPE SYNTAX Integer32 MAX-ACCESS read-only STATUS current DESCRIPTION "Numbers of TCP ESTABLISHED connections." ::= { hostStatic 3 }
END
|
|
Posted by windtear at November 18, 2004 11:13 PM