[patch] - allow the ignoring of ports/interfaces
![](https://secure.gravatar.com/avatar/19b744a2e9dbe35503607c77c877fbfe.jpg?s=120&d=mm&r=g)
Below is a small patch; it adds an extra option on the device Setting menu; which slows a list of ports - and allows the editing of the ignore flag.
This is useful on switches which are partially populated - and also makes the overview page a lot more useful.
Dw.
Index: html/includes/port-edit.inc.php =================================================================== --- html/includes/port-edit.inc.php (revision 0) +++ html/includes/port-edit.inc.php (revision 0) @@ -0,0 +1,49 @@ +<?php + +# enable/disable ports/interfaces on devices. +# + +$device_id=intval($_POST['device']); +$rows_updated = 0; + +foreach ($_POST as $key => $val) { + if (strncmp($key,"oldval_",7) == 0) { + + # Interface identifier passed as part of the field name + # + $interface_id = intval(substr($key,7)); + + $oldval = intval($val) ? 1 : 0; + $newval = $_POST['ignore_'.$interface_id] ? 1 : 0; + + # As checkboxes are not posted when unset - we effectively need to do a diff to work + # out a set->unset case. + # + if ($oldval == $newval) + continue; + + if (!mysql_query('UPDATE `ports` SET `ignore`='.$newval.' WHERE `device_id`='.$device_id.' AND `interface_id`='.$interface_id)) + $n = -1; + else + $n = mysql_affected_rows(); + + if ($n <0) { + $rows_updated = -1; + break; + }; + $rows_updated += $n; + }; +}; + + if($rows_updated > 0) { + $update_message = $rows_updated . " Device record updated."; + $updated = 1; + } elseif ($rows_updated = '-1') { + $update_message = "Device record unchanged. No update necessary."; + $updated = -1; + } else { + $update_message = "Device record update error."; + $updated = 0; + } + +?>
Property changes on: html/includes/port-edit.inc.php ___________________________________________________________________ Added: svn:executable + *
Index: html/pages/device/edit.inc.php =================================================================== --- html/pages/device/edit.inc.php (revision 1696) +++ html/pages/device/edit.inc.php (working copy) @@ -6,6 +6,7 @@
$panes = array('device' => 'Device Settings', + 'ports' => 'Port Settings', 'apps' => 'Applications', 'services' => 'Services');
Index: html/pages/device/edit/ports.inc.php =================================================================== --- html/pages/device/edit/ports.inc.php (revision 0) +++ html/pages/device/edit/ports.inc.php (revision 0) @@ -0,0 +1,51 @@ +<?php + +echo('<div style="padding: 10px;">'); + +if($_POST['ignoreport']) { + if($_SESSION['userlevel'] == '10') { + include("includes/port-edit.inc.php"); + } +} + + +if($updated && $update_message) { + print_message($update_message); +} elseif ($update_message) { + print_error($update_message); +} + +echo("<div style='float: left;'> +<form id='ignoreport' name='ignoreport' method='post' action=''> + <input type=hidden name='ignoreport' value='yes'> + <input type=hidden name=device value='".$device['device_id']."'> +<table> +<tr><th>Port</th><th>ifDescr</th><th>ifAdminStatus</th><th>ifOperStatus</th><th>Ignore</th></tr>"); + +$query = mysql_query("SELECT * FROM `ports` WHERE device_id='".$device['device_id']."' ORDER BY `ifIndex` "); +while($device = mysql_fetch_array($query)) { + echo "<tr>"; + echo "<td align=right>". $device['ifIndex']."</td>"; + echo "<td align=left>".$device['ifDescr'] . "</td>"; + echo "<td align=right>". $device['ifAdminStatus']."</td>"; + + # Mark interfaces which are down yet not ignored, or up - yet ignored - as to draw the attention + # to a possible problem. + # + $outofsync = ($device['ignore'] == ($device['ifOperStatus'] == 'down' ? 1 : 0)) ? "" : "class=red"; + + echo "<td align=right><span ".$outofsync.">". $device['ifOperStatus']."</span></td>"; + + echo "<td>"; + echo "<input type=checkbox name='ignore_".$device['interface_id']."'".($device['ignore'] ? 'checked' : '').">"; + echo "<input type=hidden name='oldval_".$device['interface_id']."' value=".($device['ignore'] ? 1 : 0).">"; + echo "</td>"; + echo "</tr>"; +} + +echo('<tr><td></td><td></td><td></td><td></td><td><input type="submit" value="Save"></td></tr>'); +echo('</table>'); +echo('</form>'); +echo('</div>'); + +?>
![](https://secure.gravatar.com/avatar/ecb2aea5855f61674508e8c889a01846.jpg?s=120&d=mm&r=g)
It'd be great if it was implemented into the code :) itself.. just a thought
mehmet
On Sep 3, 2010, at 6:16 AM, Dirk-Willem van Gulik wrote:
Below is a small patch; it adds an extra option on the device Setting menu; which slows a list of ports - and allows the editing of the ignore flag.
This is useful on switches which are partially populated - and also makes the overview page a lot more useful.
Dw.
<xx.gif>
Index: html/includes/port-edit.inc.php
--- html/includes/port-edit.inc.php (revision 0) +++ html/includes/port-edit.inc.php (revision 0) @@ -0,0 +1,49 @@ +<?php
+# enable/disable ports/interfaces on devices. +#
+$device_id=intval($_POST['device']); +$rows_updated = 0;
+foreach ($_POST as $key => $val) {
- if (strncmp($key,"oldval_",7) == 0) {
# Interface identifier passed as part of the field name
#
$interface_id = intval(substr($key,7));
$oldval = intval($val) ? 1 : 0;
$newval = $_POST['ignore_'.$interface_id] ? 1 : 0;
# As checkboxes are not posted when unset - we effectively need to do a diff to work
# out a set->unset case.
#
if ($oldval == $newval)
continue;
if (!mysql_query('UPDATE `ports` SET `ignore`='.$newval.' WHERE `device_id`='.$device_id.' AND `interface_id`='.$interface_id))
$n = -1;
else
$n = mysql_affected_rows();
if ($n <0) {
$rows_updated = -1;
break;
};
$rows_updated += $n;
- };
+};
- if($rows_updated > 0) {
- $update_message = $rows_updated . " Device record updated.";
- $updated = 1;
- } elseif ($rows_updated = '-1') {
- $update_message = "Device record unchanged. No update necessary.";
- $updated = -1;
- } else {
- $update_message = "Device record update error.";
- $updated = 0;
- }
+?>
Property changes on: html/includes/port-edit.inc.php ___________________________________________________________________ Added: svn:executable
Index: html/pages/device/edit.inc.php
--- html/pages/device/edit.inc.php (revision 1696) +++ html/pages/device/edit.inc.php (working copy) @@ -6,6 +6,7 @@
$panes = array('device' => 'Device Settings',
'services' => 'Services');'ports' => 'Port Settings', 'apps' => 'Applications',
Index: html/pages/device/edit/ports.inc.php
--- html/pages/device/edit/ports.inc.php (revision 0) +++ html/pages/device/edit/ports.inc.php (revision 0) @@ -0,0 +1,51 @@ +<?php
+echo('<div style="padding: 10px;">');
+if($_POST['ignoreport']) {
- if($_SESSION['userlevel'] == '10') {
- include("includes/port-edit.inc.php");
- }
+}
+if($updated && $update_message) {
- print_message($update_message);
+} elseif ($update_message) {
- print_error($update_message);
+}
+echo("<div style='float: left;'> +<form id='ignoreport' name='ignoreport' method='post' action=''>
<input type=hidden name='ignoreport' value='yes'>
- <input type=hidden name=device value='".$device['device_id']."'>
+<table> +<tr><th>Port</th><th>ifDescr</th><th>ifAdminStatus</th><th>ifOperStatus</th><th>Ignore</th></tr>");
+$query = mysql_query("SELECT * FROM `ports` WHERE device_id='".$device['device_id']."' ORDER BY `ifIndex` "); +while($device = mysql_fetch_array($query)) {
- echo "<tr>";
- echo "<td align=right>". $device['ifIndex']."</td>";
- echo "<td align=left>".$device['ifDescr'] . "</td>";
- echo "<td align=right>". $device['ifAdminStatus']."</td>";
- # Mark interfaces which are down yet not ignored, or up - yet ignored - as to draw the attention
- # to a possible problem.
- #
- $outofsync = ($device['ignore'] == ($device['ifOperStatus'] == 'down' ? 1 : 0)) ? "" : "class=red";
- echo "<td align=right><span ".$outofsync.">". $device['ifOperStatus']."</span></td>";
- echo "<td>";
- echo "<input type=checkbox name='ignore_".$device['interface_id']."'".($device['ignore'] ? 'checked' : '').">";
- echo "<input type=hidden name='oldval_".$device['interface_id']."' value=".($device['ignore'] ? 1 : 0).">";
- echo "</td>";
- echo "</tr>";
+}
+echo('<tr><td></td><td></td><td></td><td></td><td><input type="submit" value="Save"></td></tr>'); +echo('</table>'); +echo('</form>'); +echo('</div>');
+?>
observium mailing list observium@observium.org http://postman.memetic.org/cgi-bin/mailman/listinfo/observium
![](https://secure.gravatar.com/avatar/0fa97865a0e1ab36152b6b2299eedb49.jpg?s=120&d=mm&r=g)
I've committed this patch.
It needs a bit of cleaning up (the table and stuff is kinda ugly), but it's useful :)
thanks, adam.
On 03/09/2010 14:16, Dirk-Willem van Gulik wrote:
Below is a small patch; it adds an extra option on the device Setting menu; which slows a list of ports - and allows the editing of the ignore flag.
This is useful on switches which are partially populated - and also makes the overview page a lot more useful.
Dw.
Index: html/includes/port-edit.inc.php
--- html/includes/port-edit.inc.php (revision 0) +++ html/includes/port-edit.inc.php (revision 0) @@ -0,0 +1,49 @@ +<?php
+# enable/disable ports/interfaces on devices. +#
+$device_id=intval($_POST['device']); +$rows_updated = 0;
+foreach ($_POST as $key => $val) {
- if (strncmp($key,"oldval_",7) == 0) {
# Interface identifier passed as part of the field name
#
$interface_id = intval(substr($key,7));
$oldval = intval($val) ? 1 : 0;
$newval = $_POST['ignore_'.$interface_id] ? 1 : 0;
# As checkboxes are not posted when unset - we effectively need to do a diff to work
# out a set->unset case.
#
if ($oldval == $newval)
continue;
if (!mysql_query('UPDATE `ports` SET `ignore`='.$newval.' WHERE `device_id`='.$device_id.' AND `interface_id`='.$interface_id))
$n = -1;
else
$n = mysql_affected_rows();
if ($n<0) {
$rows_updated = -1;
break;
};
$rows_updated += $n;
- };
+};
- if($rows_updated> 0) {
- $update_message = $rows_updated . " Device record updated.";
- $updated = 1;
- } elseif ($rows_updated = '-1') {
- $update_message = "Device record unchanged. No update necessary.";
- $updated = -1;
- } else {
- $update_message = "Device record update error.";
- $updated = 0;
- }
+?>
Property changes on: html/includes/port-edit.inc.php ___________________________________________________________________ Added: svn:executable + *
Index: html/pages/device/edit.inc.php
--- html/pages/device/edit.inc.php (revision 1696) +++ html/pages/device/edit.inc.php (working copy) @@ -6,6 +6,7 @@
$panes = array('device' => 'Device Settings',
'services' => 'Services');'ports' => 'Port Settings', 'apps' => 'Applications',
Index: html/pages/device/edit/ports.inc.php
--- html/pages/device/edit/ports.inc.php (revision 0) +++ html/pages/device/edit/ports.inc.php (revision 0) @@ -0,0 +1,51 @@ +<?php
+echo('<div style="padding: 10px;">');
+if($_POST['ignoreport']) {
- if($_SESSION['userlevel'] == '10') {
- include("includes/port-edit.inc.php");
- }
+}
+if($updated&& $update_message) {
- print_message($update_message);
+} elseif ($update_message) {
- print_error($update_message);
+}
+echo("<div style='float: left;'> +<form id='ignoreport' name='ignoreport' method='post' action=''> +<input type=hidden name='ignoreport' value='yes'> +<input type=hidden name=device value='".$device['device_id']."'> +<table> +<tr><th>Port</th><th>ifDescr</th><th>ifAdminStatus</th><th>ifOperStatus</th><th>Ignore</th></tr>");
+$query = mysql_query("SELECT * FROM `ports` WHERE device_id='".$device['device_id']."' ORDER BY `ifIndex` "); +while($device = mysql_fetch_array($query)) {
- echo "<tr>";
- echo "<td align=right>". $device['ifIndex']."</td>";
- echo "<td align=left>".$device['ifDescr'] ."</td>";
- echo "<td align=right>". $device['ifAdminStatus']."</td>";
- # Mark interfaces which are down yet not ignored, or up - yet ignored - as to draw the attention
- # to a possible problem.
- #
- $outofsync = ($device['ignore'] == ($device['ifOperStatus'] == 'down' ? 1 : 0)) ? "" : "class=red";
- echo "<td align=right><span ".$outofsync.">". $device['ifOperStatus']."</span></td>";
- echo "<td>";
- echo "<input type=checkbox name='ignore_".$device['interface_id']."'".($device['ignore'] ? 'checked' : '').">";
- echo "<input type=hidden name='oldval_".$device['interface_id']."' value=".($device['ignore'] ? 1 : 0).">";
- echo "</td>";
- echo "</tr>";
+}
+echo('<tr><td></td><td></td><td></td><td></td><td><input type="submit" value="Save"></td></tr>'); +echo('</table>'); +echo('</form>'); +echo('</div>');
+?>
observium mailing list observium@observium.org http://postman.memetic.org/cgi-bin/mailman/listinfo/observium
![](https://secure.gravatar.com/avatar/0fa97865a0e1ab36152b6b2299eedb49.jpg?s=120&d=mm&r=g)
On 03/09/2010 14:52, Dirk-Willem van Gulik wrote:
Op 3 sep 2010, om 15:33 heeft Adam Armstrong het volgende geschreven:
It needs a bit of cleaning up (the table and stuff is kinda ugly), but it's useful :)
Aye - agreed. I took it from the other scripts in that section - as I was unsure how much freedom I had to 'fix' that.
Dw.
We generally don't mind people rewriting things, so long as the code retains a level of simplicity that means most people can work on it (i.e. no OOP or complex structures), as most of us aren't programmers primarily :)
There is a lot of very old and dirty code which should be rewritten, so it's not always a good idea to look at existing stuff for examples. Personally, I can't write user-interaction stuff to save my life, so it's usually terrible.
adam.
participants (3)
-
Adam Armstrong
-
Dirk-Willem van Gulik
-
Mehmet Akcin