WhyInstallation of an SNMP server providing access to management data such as networking activities, memory use, processes status, … Data will be shared read-only and protected by a simple password (aka: community string).
Build information
Ensure the following options:
[x] IPV6 IPv6 protocol support [x] MFD_REWRITES Use new MFD rewrites of mib modules [x] PERL Perl scripting language support [x] PERL_EMBEDDED Build embedded perl [x] SMUX Build with SNMP multiplexing (SMUX) support
Configuration
The SNMP daemon is configured for a read-only access from the community Password, only the MIBs which are used will be exported.
It’s possible to split the configuration in two separate files, the
first one holding a generic configuration (snmpd.conf), the
second one holding a configuration specific to the computer
(snmpd.local.conf).
snmpd.conf
The information is shared read-only and is only protected by a
password: Password.
The 2c version of the protocol is used.
The version 3 would have allowed a stronger security with the
integration of confidentiality, integrity and authentication.
# Access control
######################################################################
# sec.name source community
com2sec readonly default Password
# name sec.model sec.name
group ROSystem v2c readonly
group ROSystem usm readonly
# context sec.model sec.level match read write notif
access ROSystem "" any noauth exact system none none
Set the different level of visibility for the MIBs, the information which will be published are about the network interfaces, resources (memory, process, disk), system status (temperature) and imap.
# Views ###################################################################### # name incl/excl subtree mask view system included SNMPv2-MIB::system view system included IF-MIB::interfaces view system included IP-MIB::ipAddrTable view system included IPV6-MIB::ipv6MIB view system included HOST-RESOURCES-MIB::hrSystem view system included HOST-RESOURCES-MIB::hrStorage view system included HOST-RESOURCES-MIB::hrProcessorTable view system included UCD-SNMP-MIB::memory view system included UCD-SNMP-MIB::laTable view system included UCD-SNMP-MIB::systemStats view system included enterprises.3.6
AgentX (RFC 2741) is a protocol allowing external programs
to extend the SNMP agent with their own management information,
communication is done through the use of a UNIX socket. This will be
used, for example, by Cyrus IMAP with the OID
enterprises.3.6.
If the agentx group is not present on the system,
another appropriate group can be used (wheel, …). Or
the group can be created using a free id number, here we use the
arbitrary value of 1025:
pw groupadd agentx -g Unix group
# AgentX ###################################################################### master agentx agentXPerms 0770 0755 root agentx agentXSocket /var/agentx/master
It is also possible to extend net-snmp with a perl script thank to the
embedded interpreter. Adding CPU temperature and frequency is done
through this script, in the UCD-SNMP-MIB::systemStats branch.
# Extending ###################################################################### perl do "/usr/local/etc/snmp/health.pl"
snmpd.local.conf
syslocation and syscontact entries need
to be tailored:
# Server administrative information syslocation Server location syscontact Administrator email # Ignore all disks (avoiding potential timeout) ignoredisk /dev/*
During disk device analyses, the snmpd daemon can get stuck until a
timeout is reached. To avoid this situation the
ignoredisk directive is used.
Extending
Temperature
Extending is done at the netSnmp MIB, which is part of
UCD-SNMP-MIB::systemStats.
#!/usr/bin/perl
use BSD::Sysctl 'sysctl';
use NetSNMP::OID;
use NetSNMP::ASN;
use NetSNMP::agent;
my $rootOID = '.1.3.6.1.4.1.8072.999'; # netSnmp.999
my $cpu_freq = new NetSNMP::OID($rootOID . ".1.0");
my $cpu_temp = new NetSNMP::OID($rootOID . ".2.0");
sub myhandler {
my ($handler, $registration_info, $request_info, $requests) = @_;
for ($request = $requests; $request; $request = $request->next()) {
my $oid = $request->getOID();
my $mode = $request_info->getMode();
if ($mode == MODE_GET) {
if ($oid == $cpu_freq) {
$request->setValue(ASN_GAUGE, sysctl('dev.cpu.0.freq'));
} elsif ($oid == $cpu_temp) {
my $temp = sysctl('dev.cpu.0.temperature') / 100;
$request->setValue(ASN_OCTET_STR, "$temp");
}
} elsif ($mode == MODE_GETNEXT) {
if ($oid < $cpu_freq) {
$request->setOID($cpu_freq);
$request->setValue(ASN_GAUGE, sysctl('dev.cpu.0.freq'));
} elsif ($oid < $cpu_temp) {
my $temp = sysctl('dev.cpu.0.temperature') / 100;
$request->setOID($cpu_temp);
$request->setValue(ASN_OCTET_STR, "$temp");
}
}
}
}
my $regoid = new NetSNMP::OID($rootOID);
$agent->register("health", $regoid, \&myhandler);
Startup
To allow automatic startup, the following line is added to the
/etc/rc.conf file:
snmpd_enable="YES"
MIBs
Information can be accessed by using a name instead of it’s numerical representation (OID). For that purpose a MIB definition must be installed.
If the MIB is not already present, it must be added and made available:
-
Adding (globaly or locally):
Adding to MIBs repository cp MIB file /usr/local/share/snmp/mibs/ # Adding globaly cp MIB file $HOME/.snmp/mibs/ # Adding localy
-
Making available (one time usage, globaly, or localy):
Notify of new MIBs to use export MIBS=+Module name # One time usage echo "mibs +Module name" >> /usr/local/etc/snmp/snmpd.conf # Global usage echo "mibs +Module name" >> $HOME/.snmp/snmp.conf # Local usage