snmpv3 support. for hipsters.

git-svn-id: http://www.observium.org/svn/observer/trunk@3156 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2012-05-09 16:18:23 +00:00
parent 547a1f0fc0
commit 790480769b
9 changed files with 536 additions and 95 deletions

View File

@@ -15,14 +15,39 @@ if ($_POST['hostname'])
{
$hostname = mres($_POST['hostname']);
if ($_POST['community'])
if ($_POST['snmpver'] === "v2c" or $_POST['snmpver'] === "v1")
{
$config['snmp']['community'] = array($_POST['community']);
}
if ($_POST['community'])
{
$config['snmp']['community'] = array($_POST['community']);
}
$snmpver = mres($_POST['snmpver']);
if ($_POST['port']) { $port = mres($_POST['port']); } else { $port = "161"; }
print_message("Adding host $hostname communit" . (count($config['snmp']['community']) == 1 ? "y" : "ies") . " " . implode(', ',$config['snmp']['community']) . " port $port");
$snmpver = mres($_POST['snmpver']);
if ($_POST['port']) { $port = mres($_POST['port']); } else { $port = "161"; }
print_message("Adding host $hostname communit" . (count($config['snmp']['community']) == 1 ? "y" : "ies") . " " . implode(', ',$config['snmp']['community']) . " port $port");
}
elseif ($_POST['snmpver'] === "v3")
{
$v3 = array (
'authlevel' => mres($_POST['authlevel']),
'authname' => mres($_POST['authname']),
'authpass' => mres($_POST['authpass']),
'authalgo' => mres($_POST['authalgo']),
'cryptopass' => mres($_POST['cryptopass']),
'cryptoalgo' => mres($_POST['cryptoalgo']),
);
array_push($config['snmp']['v3'], $v3);
$snmpver = "v3";
if ($_POST['port']) { $port = mres($_POST['port']); } else { $port = "161"; }
print_message("Adding SNMPv3 host $hostname port $port");
}
else
{
print_error("Unsupported SNMP Version. There was a dropdown menu, how did you reach this error ?");
}
$result = addHost($hostname, $snmpver, $port);
if ($result)
{
@@ -45,9 +70,6 @@ $pagetitle[] = "Add host";
<tr>
<td><strong>Hostname</strong></td>
<td><input type="text" name="hostname" size="32"></td>
</tr>
<td><strong>Community</strong></td>
<td><input type="text" name="community" size="32"></td>
</tr>
<tr>
<td><strong>SNMP Version</strong></td>
@@ -55,10 +77,61 @@ $pagetitle[] = "Add host";
<select name="snmpver">
<option value="v1">v1</option>
<option value="v2c" selected>v2c</option>
<option value="v3">v3</option>
</select>
&nbsp;<strong>Port</strong> <input type="text" name="port" size="16">
</td>
</tr>
<tr>
<td colspan=2><strong>SNMPv1/2c Configuration</strong></td>
</tr>
<tr>
<td><strong>Community</strong></td>
<td><input type="text" name="community" size="32"></td>
</tr>
<tr>
<td colspan=2><strong>SNMPv3 Configuration</strong></td>
</tr>
<tr>
<td><strong>Auth Level</strong></td>
<td>
<select name="authlevel">
<option value="noAuthNoPriv" selected>NoAuthNoPriv</option>
<option value="authNoPriv">AuthNoPriv</option>
<option value="authPriv">AuthPriv</option>
</select>
</td>
</tr>
<tr>
<td><strong>Auth User Name</strong></td>
<td><input type="text" name="authname" size="32"></td>
</tr>
<tr>
<td><strong>Auth Password</strong></td>
<td><input type="text" name="authpass" size="32"></td>
</tr>
<tr>
<td><strong>Auth Algorithm</strong></td>
<td>
<select name="authalgo">
<option value="MD5" selected>MD5</option>
<option value="SHA1">SHA1</option>
</select>
</td>
</tr>
<tr>
<td><strong>Crypto Password</strong></td>
<td><input type="text" name="cryptopass" size="32"></td>
</tr>
<tr>
<td><strong>Crypto Algorithm</strong></td>
<td>
<select name="cryptoalgo">
<option value="AES" selected>AES</option>
<option value="DES">DES</option>
</select>
</td>
</tr>
<tr>
<td></td><td><input type="submit" class="submit" name="Submit" value="Add Host"></td>
</tr>

View File

@@ -9,11 +9,28 @@ if ($_POST['editing'])
$port = mres($_POST['port']);
$timeout = mres($_POST['timeout']);
$retries = mres($_POST['retries']);
$v3 = array (
'authlevel' => mres($_POST['authlevel']),
'authname' => mres($_POST['authname']),
'authpass' => mres($_POST['authpass']),
'authalgo' => mres($_POST['authalgo']),
'cryptopass' => mres($_POST['cryptopass']),
'cryptoalgo' => mres($_POST['cryptoalgo'])
);
#FIXME needs more sanity checking! and better feedback
$update = array('community' => $_POST['community'], 'snmpver' => $_POST['snmpver'], 'port' => $_POST['port']);
if ($_POST['timeout']) { $update['timeout'] = $_POST['timeout']; } else { $update['timeout'] = array('NULL'); }
if ($_POST['retries']) { $update['retries'] = $_POST['retries']; } else { $update['retries'] = array('NULL'); }
#FIXME needs better feedback
$update = array(
'community' => $community,
'snmpver' => $snmpver,
'port' => $port
);
if ($_POST['timeout']) { $update['timeout'] = $timeout; }
else { $update['timeout'] = array('NULL'); }
if ($_POST['retries']) { $update['retries'] = $retries; }
else { $update['retries'] = array('NULL'); }
$update = array_merge($update, $v3);
$rows_updated = dbUpdate($update, 'devices', '`device_id` = ?',array($device['device_id']));
@@ -47,23 +64,75 @@ echo("<br /><table cellpadding=0 cellspacing=0><tr><td>
<input type=hidden name='editing' value='yes'>
<table width='500' border='0'>
<tr>
<td width='150'><div align='right'>SNMP Community</div></td>
<td><input name='community' size='20' value='" . $device['community'] . "' />
<td><div align=right>SNMP Version</div></td>
<td>
<select name='snmpver'>
<option value='v1'>v1</option>
<option value='v2c' " . ($device['snmpver'] == 'v2c' ? 'selected' : '') . ">v2c</option>
<option value='v3' " . ($device['snmpver'] == 'v3' ? 'selected' : '') . ">v3</option>
</select>
</td>
</tr>
<div id='snmpv12'>
<!-- To be able to hide it -->
<tr>
<td><div align=right>SNMP Version</div></td>
<td><select name='snmpver'>
<option value='v1'>v1</option>
<option value='v2c'" . ($device['snmpver'] == 'v2c' ? 'selected=selected' : '') . ">v2c</option>
<td colspan='2'><strong>SNMPv1/v2c Configuration</strong></td>
</tr>
<tr>
<td width='150'><div align='right'>SNMP Community</div></td>
<td><input name='community' size='32' value='" . $device['community'] . "' />
</td>
</tr>
</div>
<div id='snmpv3'>
<!-- To be able to hide it -->
<tr>
<td colspan='2'><strong>SNMPv3 Configuration</strong></td>
</tr>
<tr>
<td width='150'><div align='right'>Auth Level</div></td>
<td>
<select name='authlevel'>
<option value='NoAuthNoPriv'>NoAuthNoPriv</option>
<option value='AuthNoPriv' " . ($device['authlevel'] == "authNoPriv" ? 'selected' : '') . ">AuthNoPriv</option>
<option value='AuthPriv' " . ($device['authlevel'] == "authPriv" ? 'selected' : '') . ">AuthPriv</option>
</select>
</td>
</tr>
<tr>
<td><div align='right'>SNMP Port</div></td>
<td><input name='port' size='20' value='" . $device['port'] . "' />
<td width='150'><div align='right'>Auth User Name</div></td>
<td><input type='text' name='authname' size='32' value='" . $device['authname'] . "'></td>
</tr>
<tr>
<td width='150'><div align='right'>Auth Password</div></td>
<td><input type='text' name='authpass' size='32' value='" . $device['authpass'] . "'></td>
</tr>
<tr>
<td width='150'><div align='right'>Auth Algorithm</strong></td>
<td>
<select name='authalgo'>
<option value='MD5'>MD5</option>
<option value='SHA1' " . ($device['authalgo'] === "SHA1" ? 'selected' : '') . ">SHA1</option>
</select>
</td>
</tr>
<tr>
<td width='150'><div align='right'>Crypto Password</div></td>
<td><input type='text' name='cryptopass' size='32' value='" . $device['cryptopass'] . "'></td>
</tr>
<tr>
<td width='150'><div align='right'>Crypto Algorithm</div></td>
<td>
<select name='cryptoalgo'>
<option value='AES'>AES</option>
<option value='DES' " . ($device['cryptoalgo'] === "DES" ? 'selected' : '') . ">DES</option>
</select>
</td>
</tr>
</div>
<tr>
<td colspan='2'><strong>SNMP Connectivity</strong></td>
</tr>
<tr>
<td><div align='right'>SNMP Transport</div></td>
<td>
@@ -79,15 +148,20 @@ foreach ($config['snmp']['transports'] as $transport)
echo(" </select>
</td>
</tr>
<tr>
<td><div align='right'>SNMP Port</div></td>
<td><input name='port' size='32' value='" . $device['port'] . "' />
</td>
</tr>
<tr>
<td><div align='right'>SNMP Timeout</div></td>
<td><input name='timeout' size='20' value='" . ($device['timeout'] ? $device['timeout'] : '') . "' />&nbsp;
<td><input name='timeout' size='32' value='" . ($device['timeout'] ? $device['timeout'] : '') . "' />&nbsp;
<em>(milli)seconds</em>
</td>
</tr>
<tr>
<td><div align='right'>SNMP Retries</div></td>
<td colspan='3'><input name='retries' size='20' value='" . ($device['timeout'] ? $device['retries'] : '') . "' />
<td colspan='3'><input name='retries' size='32' value='" . ($device['timeout'] ? $device['retries'] : '') . "' />
</td>
</tr>");