mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	add a distinction between ignore and disable for ports, like for devices - patch by Paul Gear
git-svn-id: http://www.observium.org/svn/observer/trunk@1942 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
		@@ -13,6 +13,7 @@ ALTER TABLE `vrfs` CHANGE `mplsVpnVrfRouteDistinguisher` `mplsVpnVrfRouteDisting
 | 
			
		||||
## Change port rrds
 | 
			
		||||
ALTER TABLE  `devices` ADD  `timeout` INT NULL DEFAULT NULL AFTER  `port`;
 | 
			
		||||
ALTER TABLE `devices` ADD `retries` INT NULL DEFAULT NULL AFTER `timeout`;
 | 
			
		||||
ALTER TABLE `ports` ADD `disabled` tinyint(1) NOT NULL DEFAULT '0' AFTER `ignore`;
 | 
			
		||||
ALTER TABLE  `perf_times` CHANGE  `duration`  `duration` DOUBLE( 8, 2 ) NOT NULL
 | 
			
		||||
ALTER TABLE `sensors` ADD `poller_type` VARCHAR(16) NOT NULL DEFAULT 'snmp' AFTER `device_id`;
 | 
			
		||||
## Add transport
 | 
			
		||||
 
 | 
			
		||||
@@ -7,24 +7,58 @@ $rows_updated = 0;
 | 
			
		||||
 | 
			
		||||
foreach ($_POST as $key => $val)
 | 
			
		||||
{
 | 
			
		||||
  if (strncmp($key,"oldval_",7) == 0)
 | 
			
		||||
  if (strncmp($key,"oldign_",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;
 | 
			
		||||
    $oldign = intval($val) ? 1 : 0;
 | 
			
		||||
    $newign = $_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)
 | 
			
		||||
    if ($oldign == $newign)
 | 
			
		||||
    {
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!mysql_query('UPDATE `ports` SET `ignore`='.$newval.' WHERE `device_id`='.$device_id.' AND `interface_id`='.$interface_id))
 | 
			
		||||
    if (!mysql_query('UPDATE `ports` SET `ignore`='.$newign.' 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;
 | 
			
		||||
  }
 | 
			
		||||
  elseif (strncmp($key,"olddis_",7) == 0)
 | 
			
		||||
  {
 | 
			
		||||
    # Interface identifier passed as part of the field name
 | 
			
		||||
 | 
			
		||||
    $interface_id = intval(substr($key,7));
 | 
			
		||||
 | 
			
		||||
    $olddis = intval($val) ? 1 : 0;
 | 
			
		||||
    $newdis = $_POST['disabled_'.$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 ($olddis == $newdis)
 | 
			
		||||
    {
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!mysql_query('UPDATE `ports` SET `disabled`='.$newdis.' WHERE `device_id`='.$device_id.' AND `interface_id`='.$interface_id))
 | 
			
		||||
    {
 | 
			
		||||
      $n = -1;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,8 @@ echo("<div style='float: left;'>
 | 
			
		||||
  <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>");
 | 
			
		||||
<tr><th>Port</th><th>ifDescr</th><th>ifAdminStatus</th><th>ifOperStatus</th><th>Disable</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))
 | 
			
		||||
@@ -32,18 +33,26 @@ while ($device = mysql_fetch_array($query))
 | 
			
		||||
  echo("<td align=left>".$device['ifDescr'] . "</td>");
 | 
			
		||||
  echo("<td align=right>". $device['ifAdminStatus']."</td>");
 | 
			
		||||
 | 
			
		||||
  # Mark interfaces which are OperDown (but not AdminDown) yet not ignored, or up - yet ignored - as to draw the attention
 | 
			
		||||
  # to a possible problem.
 | 
			
		||||
  #
 | 
			
		||||
  $outofsync =  ($device['ignore'] == ($device['ifOperStatus'] == 'down' && $device['ifAdminStatus'] != 'down' ? 1 : 0))  ? "" : "class=red";
 | 
			
		||||
  # Mark interfaces which are OperDown (but not AdminDown) yet not ignored or disabled, or up yet ignored or disabled
 | 
			
		||||
  # - as to draw the attention to a possible problem.
 | 
			
		||||
  $isportbad = ($device['ifOperStatus'] == 'down' && $device['ifAdminStatus'] != 'down') ? 1 : 0;
 | 
			
		||||
  $dowecare  = ($device['ignore'] == 0 && $device['disabled'] == 0) ? 1 : 0;
 | 
			
		||||
  $outofsync = ($isportbad && $dowecare) ? "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("<input type=checkbox name='disabled_".$device['interface_id']."'".($device['disabled'] ? 'checked' : '').">");
 | 
			
		||||
  echo("<input type=hidden name='olddis_".$device['interface_id']."' value=".($device['disabled'] ? 1 : 0).">");
 | 
			
		||||
  echo("</td>");
 | 
			
		||||
  echo("</tr>");
 | 
			
		||||
 | 
			
		||||
  echo("<td>");
 | 
			
		||||
  echo("<input type=checkbox name='ignore_".$device['interface_id']."'".($device['ignore'] ? 'checked' : '').">");
 | 
			
		||||
  echo("<input type=hidden name='oldign_".$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>');
 | 
			
		||||
 
 | 
			
		||||
@@ -102,7 +102,7 @@ $port_query = mysql_query("SELECT * FROM `ports` WHERE `device_id` = '".$device[
 | 
			
		||||
while ($port = mysql_fetch_array($port_query))
 | 
			
		||||
{
 | 
			
		||||
  echo("Port " . $port['ifDescr'] . " ");
 | 
			
		||||
  if ($port_stats[$port['ifIndex']] && $port['ignore'] == "0")
 | 
			
		||||
  if ($port_stats[$port['ifIndex']] && $port['disabled'] == "0")
 | 
			
		||||
  { // Check to make sure Port data is cached.
 | 
			
		||||
    $this_port = &$port_stats[$port['ifIndex']];
 | 
			
		||||
 | 
			
		||||
@@ -282,7 +282,7 @@ while ($port = mysql_fetch_array($port_query))
 | 
			
		||||
    unset($update_query); unset($update);
 | 
			
		||||
 | 
			
		||||
    // Send alerts for interface flaps.
 | 
			
		||||
    if ($config['warn']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus']))
 | 
			
		||||
    if ($config['warn']['ifdown'] && ($port['ifOperStatus'] != $this_port['ifOperStatus']) && $port['ignore'] == 0)
 | 
			
		||||
    {
 | 
			
		||||
      if ($this_port['ifAlias'])
 | 
			
		||||
      {
 | 
			
		||||
@@ -301,12 +301,12 @@ while ($port = mysql_fetch_array($port_query))
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  elseif ($port['ignore'] == "0")
 | 
			
		||||
  elseif ($port['disabled'] == "0")
 | 
			
		||||
  {
 | 
			
		||||
    echo("Port Deleted"); // Port missing from SNMP cache.
 | 
			
		||||
    mysql_query("UPDATE `ports` SET `deleted` = '1' WHERE `device_id` = '".$device['device_id']."' AND `ifIndex` = '".$this_port['ifIndex']."'");
 | 
			
		||||
  } else {
 | 
			
		||||
    echo("Port Ignored.");
 | 
			
		||||
    echo("Port Disabled.");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  echo("\n");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user