Commit a4882df9 authored by Franco Fichtner's avatar Franco Fichtner

snmp: corrections for #1256

parent d0206619
...@@ -1796,7 +1796,7 @@ function services_dnsmasq_configure($verbose = false) ...@@ -1796,7 +1796,7 @@ function services_dnsmasq_configure($verbose = false)
} }
if ($verbose) { if ($verbose) {
echo 'Starting DNS forwarder...'; echo 'Starting DNS Forwarder...';
flush(); flush();
} }
...@@ -1917,7 +1917,7 @@ function services_unbound_configure($verbose = false) ...@@ -1917,7 +1917,7 @@ function services_unbound_configure($verbose = false)
} }
if ($verbose) { if ($verbose) {
echo "Starting DNS Resolver..."; echo 'Starting DNS Resolver...';
flush(); flush();
} }
...@@ -1928,41 +1928,37 @@ function services_unbound_configure($verbose = false) ...@@ -1928,41 +1928,37 @@ function services_unbound_configure($verbose = false)
} }
} }
function services_snmpd_configure() function services_snmpd_configure($verbose = false)
{ {
global $config, $g; global $config, $g;
/* kill any running snmpd */ killbypid('/var/run/snmpd.pid', 'TERM', true);
killbypid('/var/run/snmpd.pid');
sleep(2);
if (is_process_running('bsnmpd')) { if (!isset($config['snmpd']['enable'])) {
mwexec('/usr/bin/killall bsnmpd', true); return;
} }
if (isset($config['snmpd']['enable'])) { if ($verbose) {
if (file_exists("/var/run/booting")) { echo 'Starting SNMP daemon....';
echo gettext("Starting SNMP daemon... "); flush();
} }
/* generate snmpd.conf */
$fd = fopen("/var/etc/snmpd.conf", "w");
if (!$fd) {
log_error('Cannot open snmpd.conf in services_snmpd_configure()');
return 1;
}
/* generate snmpd.conf */
$fd = fopen("/var/etc/snmpd.conf", "w");
if (!$fd) {
log_error('Cannot open snmpd.conf in services_snmpd_configure()');
return;
}
$snmpdconf = <<<EOD $snmpdconf = <<<EOD
location := "{$config['snmpd']['syslocation']}" location := "{$config['snmpd']['syslocation']}"
contact := "{$config['snmpd']['syscontact']}" contact := "{$config['snmpd']['syscontact']}"
read := "{$config['snmpd']['rocommunity']}" read := "{$config['snmpd']['rocommunity']}"
EOD; EOD;
if (isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){
if (isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){ $snmpdconf .= <<<EOD
$snmpdconf .= <<<EOD
# SNMP Trap support. # SNMP Trap support.
traphost := {$config['snmpd']['trapserver']} traphost := {$config['snmpd']['trapserver']}
trapport := {$config['snmpd']['trapserverport']} trapport := {$config['snmpd']['trapserverport']}
...@@ -1970,15 +1966,15 @@ trap := "{$config['snmpd']['trapstring']}" ...@@ -1970,15 +1966,15 @@ trap := "{$config['snmpd']['trapstring']}"
EOD; EOD;
} }
$version = trim(file_get_contents('/usr/local/opnsense/version/opnsense')); $version = trim(file_get_contents('/usr/local/opnsense/version/opnsense'));
$platform = $g['product_name']; $platform = $g['product_name'];
$sysDescr = "{$g['product_name']} " . php_uname("n") . $sysDescr = "{$g['product_name']} " . php_uname("n") .
" {$version} {$platform} " . php_uname("s") . " {$version} {$platform} " . php_uname("s") .
" " . php_uname("r") . " " . trim(shell_exec('uname -p')); " " . php_uname("r") . " " . trim(shell_exec('uname -p'));
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
system := 1 system := 1
%snmpd %snmpd
sysDescr = "{$sysDescr}" sysDescr = "{$sysDescr}"
...@@ -1988,42 +1984,41 @@ begemotSnmpdCommunityString.0.1 = $(read) ...@@ -1988,42 +1984,41 @@ begemotSnmpdCommunityString.0.1 = $(read)
EOD; EOD;
if (isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){ if (isset($config['snmpd']['trapenable']) && preg_match('/^\S+$/', $config['snmpd']['trapserver'])){
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4 begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4
begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2 begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2
begemotTrapSinkComm.[$(traphost)].$(trapport) = $(trap) begemotTrapSinkComm.[$(traphost)].$(trapport) = $(trap)
EOD; EOD;
} }
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdCommunityDisable = 1 begemotSnmpdCommunityDisable = 1
EOD; EOD;
$bind_to_ip = "0.0.0.0"; $bind_to_ip = "0.0.0.0";
if (isset($config['snmpd']['bindip'])) { if (isset($config['snmpd']['bindip'])) {
if (is_ipaddr($config['snmpd']['bindip'])) { if (is_ipaddr($config['snmpd']['bindip'])) {
$bind_to_ip = $config['snmpd']['bindip']; $bind_to_ip = $config['snmpd']['bindip'];
} else { } else {
$if = get_real_interface($config['snmpd']['bindip']); $if = get_real_interface($config['snmpd']['bindip']);
if (does_interface_exist($if)) { if (does_interface_exist($if)) {
$bind_to_ip = find_interface_ip($if); $bind_to_ip = find_interface_ip($if);
}
} }
} }
}
if (is_port( $config['snmpd']['pollport'] )) { if (is_port( $config['snmpd']['pollport'] )) {
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdPortStatus.{$bind_to_ip}.{$config['snmpd']['pollport']} = 1 begemotSnmpdPortStatus.{$bind_to_ip}.{$config['snmpd']['pollport']} = 1
EOD; EOD;
} }
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdLocalPortStatus."/var/run/snmpd.sock" = 1 begemotSnmpdLocalPortStatus."/var/run/snmpd.sock" = 1
begemotSnmpdLocalPortType."/var/run/snmpd.sock" = 4 begemotSnmpdLocalPortType."/var/run/snmpd.sock" = 4
...@@ -2036,71 +2031,67 @@ snmpEnableAuthenTraps = 2 ...@@ -2036,71 +2031,67 @@ snmpEnableAuthenTraps = 2
EOD; EOD;
if (is_array( $config['snmpd']['modules'] )) { if (is_array( $config['snmpd']['modules'] )) {
if (isset($config['snmpd']['modules']['mibii'])) { if (isset($config['snmpd']['modules']['mibii'])) {
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdModulePath."mibII" = "/usr/lib/snmp_mibII.so" begemotSnmpdModulePath."mibII" = "/usr/lib/snmp_mibII.so"
EOD; EOD;
} }
if (isset($config['snmpd']['modules']['netgraph'])) { if (isset($config['snmpd']['modules']['netgraph'])) {
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so" begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so"
%netgraph %netgraph
begemotNgControlNodeName = "snmpd" begemotNgControlNodeName = "snmpd"
EOD; EOD;
} }
if (isset($config['snmpd']['modules']['pf'])) { if (isset($config['snmpd']['modules']['pf'])) {
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdModulePath."pf" = "/usr/lib/snmp_pf.so" begemotSnmpdModulePath."pf" = "/usr/lib/snmp_pf.so"
EOD; EOD;
} }
if (isset($config['snmpd']['modules']['hostres'])) { if (isset($config['snmpd']['modules']['hostres'])) {
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdModulePath."hostres" = "/usr/lib/snmp_hostres.so" begemotSnmpdModulePath."hostres" = "/usr/lib/snmp_hostres.so"
EOD; EOD;
} }
if (isset($config['snmpd']['modules']['bridge'])) { if (isset($config['snmpd']['modules']['bridge'])) {
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdModulePath."bridge" = "/usr/lib/snmp_bridge.so" begemotSnmpdModulePath."bridge" = "/usr/lib/snmp_bridge.so"
# config must end with blank line # config must end with blank line
EOD; EOD;
} }
if (isset($config['snmpd']['modules']['ucd'])) { if (isset($config['snmpd']['modules']['ucd'])) {
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so" begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so"
EOD; EOD;
} }
if (isset($config['snmpd']['modules']['regex'])) { if (isset($config['snmpd']['modules']['regex'])) {
$snmpdconf .= <<<EOD $snmpdconf .= <<<EOD
begemotSnmpdModulePath."regex" = "/usr/local/lib/snmp_regex.so" begemotSnmpdModulePath."regex" = "/usr/local/lib/snmp_regex.so"
EOD; EOD;
}
} }
}
fwrite($fd, $snmpdconf); fwrite($fd, $snmpdconf);
fclose($fd); fclose($fd);
unset($snmpdconf); unset($snmpdconf);
/* run bsnmpd */ /* run bsnmpd */
mwexec("/usr/sbin/bsnmpd -c /var/etc/snmpd.conf -p /var/run/snmpd.pid"); mwexec("/usr/sbin/bsnmpd -c /var/etc/snmpd.conf -p /var/run/snmpd.pid");
if (file_exists("/var/run/booting")) { if ($verbose) {
echo gettext("done.") . "\n"; echo "done.\n";
}
} }
return 0;
} }
function services_dnsupdate_process($int = '', $updatehost = '', $forced = false) function services_dnsupdate_process($int = '', $updatehost = '', $forced = false)
......
...@@ -223,7 +223,7 @@ if (function_exists('plugins_configure')) { ...@@ -223,7 +223,7 @@ if (function_exists('plugins_configure')) {
$ipsec_dynamic_hosts = ipsec_configure(); $ipsec_dynamic_hosts = ipsec_configure();
/* start SNMP service */ /* start SNMP service */
services_snmpd_configure(); services_snmpd_configure(true);
/* load graphing functions */ /* load graphing functions */
enable_rrd_graphing(true); enable_rrd_graphing(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment