mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	Added discovery for ups-nut status (#11606)
* Added UPS NUT state sensors * Added UPS NUT state sensors * Added UPS NUT state sensors * Added UPS NUT state sensors * Added UPS NUT state sensors * Update linux_ups-nut.snmprec * Fixed UPS states so making alerts easier. * Fixed * Actually Fixed it * Added alert rules for UPS-NUT
This commit is contained in:
		@@ -25,3 +25,5 @@
 | 
			
		||||
 | 
			
		||||
echo 'RaspberryPi ';
 | 
			
		||||
$pre_cache['raspberry_pi_sensors'] = snmpwalk_cache_oid($device, '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121', [], "NET-SNMP-EXTEND-MIB");
 | 
			
		||||
echo 'ups-nut ';
 | 
			
		||||
$pre_cache['ups_nut_sensors'] = snmpwalk_cache_oid($device, '.1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116', [], "NET-SNMP-EXTEND-MIB");
 | 
			
		||||
 
 | 
			
		||||
@@ -42,3 +42,47 @@ if (!empty($pre_cache['raspberry_pi_sensors'])) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (!empty($pre_cache['ups_nut_sensors'])) {
 | 
			
		||||
    /*
 | 
			
		||||
    * All the possible states from https://networkupstools.org/docs/developer-guide.chunked/ar01s04.html#_status_data
 | 
			
		||||
    */
 | 
			
		||||
    $sensors = [
 | 
			
		||||
        ['state_name' => 'UPSOnLine'            , 'genericT' => 0, 'genericF' => 1, 'descr' => 'UPS on line'],
 | 
			
		||||
        ['state_name' => 'UPSOnBattery'         , 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS on battery'],
 | 
			
		||||
        ['state_name' => 'UPSLowBattery'        , 'genericT' => 2, 'genericF' => 0, 'descr' => 'UPS low battery'],
 | 
			
		||||
        ['state_name' => 'UPSHighBattery'       , 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS high battery'],
 | 
			
		||||
        ['state_name' => 'UPSBatteryReplace'    , 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS the battery needs to be replaced'],
 | 
			
		||||
        ['state_name' => 'UPSBatteryCharging'   , 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS the battery is charging'],
 | 
			
		||||
        ['state_name' => 'UPSBatteryDischarging', 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS the battery is discharging'],
 | 
			
		||||
        ['state_name' => 'UPSUPSBypass'         , 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS bypass circuit is active' ],
 | 
			
		||||
        ['state_name' => 'UPSRuntimeCalibration', 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS is currently performing runtime calibration'],
 | 
			
		||||
        ['state_name' => 'UPSOffline'           , 'genericT' => 2, 'genericF' => 0, 'descr' => 'UPS is offline and is not supplying power to the load'],
 | 
			
		||||
        ['state_name' => 'UPSUPSOverloaded'     , 'genericT' => 2, 'genericF' => 0, 'descr' => 'UPS is overloaded.'],
 | 
			
		||||
        ['state_name' => 'UPSUPSBuck'           , 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS is trimming incoming voltage'],
 | 
			
		||||
        ['state_name' => 'UPSUPSBoost'          , 'genericT' => 1, 'genericF' => 0, 'descr' => 'UPS is boosting incoming voltage'],
 | 
			
		||||
        ['state_name' => 'UPSForcedShutdown'    , 'genericT' => 2, 'genericF' => 0, 'descr' => 'UPS forced shutdown'],
 | 
			
		||||
    ];
 | 
			
		||||
    foreach ($sensors as $index => $sensor) {
 | 
			
		||||
        $sensor_oid = 9 + $index;
 | 
			
		||||
        $oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.'. strval($sensor_oid);
 | 
			
		||||
        $value = current($pre_cache['ups_nut_sensors']["ups-nut." . $sensor_oid]);
 | 
			
		||||
        
 | 
			
		||||
        if (!empty($value) or $value == "0") {
 | 
			
		||||
            $state_name = $sensor['state_name'];
 | 
			
		||||
            $descr = $sensor['descr'];
 | 
			
		||||
            $states = [
 | 
			
		||||
                ['value' => 0, 'generic' => $sensor['genericF'], 'graph' => 1, 'descr' => 'False'],
 | 
			
		||||
                ['value' => 1, 'generic' => $sensor['genericT'], 'graph' => 1, 'descr' => 'True']
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
            create_state_index($state_name, $states);
 | 
			
		||||
 | 
			
		||||
            //Discover Sensors
 | 
			
		||||
            discover_sensor($valid['sensor'], 'state', $device, $oid, $sensor_oid, $state_name, $descr, '1', '1', null, null, null, null, $value, 'snmp', $sensor_oid);
 | 
			
		||||
 | 
			
		||||
            //Create Sensor To State Index
 | 
			
		||||
            create_sensor_to_state_index($device, $state_name, $sensor_oid);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -42,8 +42,31 @@ if (!$ups_nut) {
 | 
			
		||||
 | 
			
		||||
echo ' '.$name;
 | 
			
		||||
 | 
			
		||||
// (2016-11-25, R.Morris) Correct list and data below, to match latest ups-nut.sh script (missing one input, and misaligned).
 | 
			
		||||
list ($charge, $battery_low, $remaining, $bat_volt, $bat_nom, $line_nom, $input_volt, $load) = explode("\n", $ups_nut);
 | 
			
		||||
// (2020-05-13, Jon.W) Added ups status data and updated ups-nut.sh script.
 | 
			
		||||
list (
 | 
			
		||||
    $charge,
 | 
			
		||||
    $battery_low,
 | 
			
		||||
    $remaining,
 | 
			
		||||
    $bat_volt,
 | 
			
		||||
    $bat_nom,
 | 
			
		||||
    $line_nom,
 | 
			
		||||
    $input_volt,
 | 
			
		||||
    $load,
 | 
			
		||||
    $UPSOnLine,
 | 
			
		||||
    $UPSOnBattery,
 | 
			
		||||
    $UPSLowBattery,
 | 
			
		||||
    $UPSHighBattery,
 | 
			
		||||
    $UPSBatteryReplace,
 | 
			
		||||
    $UPSBatteryCharging,
 | 
			
		||||
    $UPSBatteryDischarging,
 | 
			
		||||
    $UPSUPSBypass,
 | 
			
		||||
    $UPSRuntimeCalibration,
 | 
			
		||||
    $UPSOffline,
 | 
			
		||||
    $UPSUPSOverloaded,
 | 
			
		||||
    $UPSUPSBuck,
 | 
			
		||||
    $UPSUPSBoost,
 | 
			
		||||
    $UPSForcedShutdown
 | 
			
		||||
    ) = explode("\n", $ups_nut);
 | 
			
		||||
 | 
			
		||||
$rrd_name = array('app', $name, $app_id);
 | 
			
		||||
$rrd_def = RrdDefinition::make()
 | 
			
		||||
@@ -67,6 +90,28 @@ $fields = array(
 | 
			
		||||
    'load' => $load
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
$sensors = [
 | 
			
		||||
    ['state_name' => 'UPSOnLine'            , 'value' => $UPSOnLine],
 | 
			
		||||
    ['state_name' => 'UPSOnBattery'         , 'value' => $UPSOnBattery],
 | 
			
		||||
    ['state_name' => 'UPSLowBattery'        , 'value' => $UPSLowBattery],
 | 
			
		||||
    ['state_name' => 'UPSHighBattery'       , 'value' => $UPSHighBattery],
 | 
			
		||||
    ['state_name' => 'UPSBatteryReplace'    , 'value' => $UPSBatteryReplace],
 | 
			
		||||
    ['state_name' => 'UPSBatteryCharging'   , 'value' => $UPSBatteryCharging],
 | 
			
		||||
    ['state_name' => 'UPSBatteryDischarging', 'value' => $UPSBatteryDischarging],
 | 
			
		||||
    ['state_name' => 'UPSUPSBypass'         , 'value' => $UPSUPSBypass],
 | 
			
		||||
    ['state_name' => 'UPSRuntimeCalibration', 'value' => $UPSRuntimeCalibration],
 | 
			
		||||
    ['state_name' => 'UPSOffline'           , 'value' => $UPSOffline],
 | 
			
		||||
    ['state_name' => 'UPSUPSOverloaded'     , 'value' => $UPSUPSOverloaded],
 | 
			
		||||
    ['state_name' => 'UPSUPSBuck'           , 'value' => $UPSUPSBuck],
 | 
			
		||||
    ['state_name' => 'UPSUPSBoost'          , 'value' => $UPSUPSBoost],
 | 
			
		||||
    ['state_name' => 'UPSForcedShutdown'    , 'value' => $UPSForcedShutdown]
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
foreach ($sensors as $index => $sensor) {
 | 
			
		||||
    $rrd_def->addDataset($sensor['state_name'], 'GAUGE', 0);
 | 
			
		||||
    $fields[$sensor['state_name']]= $sensor['value'];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
 | 
			
		||||
data_update($device, 'app', $tags, $fields);
 | 
			
		||||
update_application($app, $ups_nut, $fields);
 | 
			
		||||
 
 | 
			
		||||
@@ -456,5 +456,57 @@
 | 
			
		||||
    "name": "CustomOID under warning limit",
 | 
			
		||||
    "severity": "warning",
 | 
			
		||||
    "default": true
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSOnBattery\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT on battery"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSLowBattery\" AND macros.state_sensor_critical = 1",
 | 
			
		||||
    "name": "UPS-NUT low battery"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSHighBattery\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT high battery"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSBatteryReplace\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT battery needs to be replaced"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSBatteryCharging\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT battery is charging"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSBatteryDischarging\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT battery is discharging"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSUPSBypass\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT bypass circuit is active"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSRuntimeCalibration\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT performing runtime calibration"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSOffline\" AND macros.state_sensor_critical = 1",
 | 
			
		||||
    "name": "UPS-NUT offline and is not supplying power to the load"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSUPSOverloaded\" AND macros.state_sensor_critical = 1",
 | 
			
		||||
    "name": "UPS-NUT overloaded"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSUPSBuck\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT trimming incoming voltage"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSUPSBoost\" AND macros.state_sensor_warning = 1",
 | 
			
		||||
    "name": "UPS-NUT boosting incoming voltage"
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    "rule": "applications.app_type = \"ups-nut\" AND state_indexes.state_name = \"UPSForcedShutdown\" AND macros.state_sensor_critical = 1",
 | 
			
		||||
    "name": "UPS-NUT trimming incoming voltage"
 | 
			
		||||
  }
 | 
			
		||||
]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1454
									
								
								tests/data/linux_ups-nut.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1454
									
								
								tests/data/linux_ups-nut.json
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										27
									
								
								tests/snmpsim/linux_ups-nut.snmprec
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								tests/snmpsim/linux_ups-nut.snmprec
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
1.3.6.1.2.1.1.1.0|4|Linux some.host.name 4.9.0 #1 SMP Mon Dec 12 14:44:53 CST 2016 x86_64
 | 
			
		||||
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.8072.3.2.10
 | 
			
		||||
1.3.6.1.2.1.1.3.0|67|17827727
 | 
			
		||||
1.3.6.1.2.1.1.4.0|4|<private>
 | 
			
		||||
1.3.6.1.2.1.1.5.0|4|<private>
 | 
			
		||||
1.3.6.1.2.1.1.6.0|4|<private>
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.1|4|100
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.3|4|2280
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.4|4|44
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.5|4|45
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.6|4|230
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.7|4|252.0
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.8|4|17
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.9|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.10|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.11|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.12|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.13|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.14|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.15|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.16|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.17|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.18|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.19|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.20|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.21|4|1
 | 
			
		||||
1.3.6.1.4.1.8072.1.3.2.4.1.2.7.117.112.115.45.110.117.116.22|4|1
 | 
			
		||||
		Reference in New Issue
	
	Block a user