Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-plugins
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cscf
icinga-plugins
Commits
509696d8
Commit
509696d8
authored
1 year ago
by
root
Browse files
Options
Downloads
Patches
Plain Diff
check_ups_eaton converted to Python3 with easysnmp library.
parent
8288c98d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_ups_eaton
+51
-33
51 additions, 33 deletions
check_ups_eaton
with
51 additions
and
33 deletions
check_ups_eaton
+
51
−
33
View file @
509696d8
#!/usr/bin/python
#!/usr/bin/python
3
# Author: Devon Merner (dmerner)
# Date: November 5th, 2021
...
...
@@ -23,7 +23,8 @@ PERFDATA = ""
import
sys
import
argparse
import
netsnmp
from
easysnmp
import
Session
from
easysnmp.exceptions
import
*
# Basic OIDs
xupsIdentModel
=
"
.1.3.6.1.2.1.33.1.1.2.0
"
...
...
@@ -118,7 +119,21 @@ args = {
def
FtoC
(
temp
):
return
(
temp
-
32
)
*
5
/
9
systemModel
=
netsnmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsIdentModel
),
**
args
)[
0
]
def
snmpGet
(
oid
):
try
:
return
session
.
get
(
oid
).
value
except
EasySNMPNoSuchNameError
:
return
None
def
snmpWalk
(
oid
):
try
:
return
session
.
walk
(
oid
)
except
EasySNMPNoSuchNameError
:
return
None
session
=
Session
(
hostname
=
options
.
host
,
community
=
options
.
community
,
version
=
int
(
options
.
version
))
systemModel
=
snmpGet
(
xupsIdentModel
)
if
systemModel
is
None
:
print
(
STATE_LABEL
[
STATE_UNKNOWN
]
+
"
-
"
+
options
.
host
+
"
did not respond to the SNMP query.
"
)
...
...
@@ -126,40 +141,39 @@ if systemModel is None:
OUTPUT_TEXT
+=
"
(
"
+
str
(
systemModel
)
+
"
)
"
temperatureOutput
=
netsnmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsEnvAmbientTemp
)
,
**
args
)[
0
]
temperatureOutput
=
session
.
get
(
xupsEnvAmbientTemp
)
.
value
if
temperatureOutput
:
envTemperature
=
float
(
temperatureOutput
)
xupsBatteryAbmStatus
=
int
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsBatteryAbmStatus
)
,
**
args
)[
0
]
)
xupsBatteryStatus
=
int
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsBatteryStatus
)
,
**
args
)[
0
]
)
xupsBatteryLastReplacedDate
=
str
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsBatteryLastReplacedDate
)
,
**
args
)[
0
]
)
xupsBatCapacity
=
float
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsBatCapacity
)
,
**
args
)[
0
]
)
xupsBatTimeRemaining
=
int
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsBatTimeRemaining
)
,
**
args
)[
0
]
)
xupsBatVoltage
=
int
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsBatVoltage
)
,
**
args
)[
0
]
)
xupsBatCurrent
=
int
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsBatCurrent
)
,
**
args
)[
0
]
)
xupsBatteryAbmStatus
=
int
(
snmp
Get
(
xupsBatteryAbmStatus
))
xupsBatteryStatus
=
int
(
snmp
Get
(
xupsBatteryStatus
))
xupsBatteryLastReplacedDate
=
str
(
snmp
Get
(
xupsBatteryLastReplacedDate
))
xupsBatCapacity
=
float
(
snmp
Get
(
xupsBatCapacity
))
xupsBatTimeRemaining
=
int
(
snmp
Get
(
xupsBatTimeRemaining
))
xupsBatVoltage
=
int
(
snmp
Get
(
xupsBatVoltage
))
xupsBatCurrent
=
int
(
snmp
Get
(
xupsBatCurrent
))
# Determine the amount of input phases
xupsInputPhase
=
netsnmp
.
snmpwalk
(
netsnmp
.
Varbind
(
xupsInputPhase
),
**
args
)
xupsInputFrequency
=
int
(
netsnmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsInputFrequency
),
**
args
)[
0
])
/
10
# 0.1 Hertz
xupsInputSource
=
int
(
netsnmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsInputSource
),
**
args
)[
0
])
xupsInputPhase
=
snmpWalk
(
xupsInputPhase
)
xupsInputFrequency
=
int
(
snmpGet
(
xupsInputFrequency
))
/
10
# 0.1 Hertz
xupsInputSource
=
int
(
snmpGet
(
xupsInputSource
))
# Determine the amount of output phases
xupsOutputPhase
=
net
snmp
.
snmpwalk
(
netsnmp
.
Varbind
(
xupsOutputPhase
)
,
**
args
)
xupsOutputSource
=
int
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsOutputSource
)
,
**
args
)[
0
]
)
xupsOutputPhase
=
snmp
Walk
(
xupsOutputPhase
)
xupsOutputSource
=
int
(
snmp
Get
(
xupsOutputSource
))
# Dynamic input variables
xupsInputVoltage
=
net
snmp
.
snmpwalk
(
netsnmp
.
Varbind
(
xupsInputVoltage
)
,
**
args
)
xupsInputCurrent
=
net
snmp
.
snmpwalk
(
netsnmp
.
Varbind
(
xupsInputCurrent
)
,
**
args
)
xupsInputWatts
=
net
snmp
.
snmpwalk
(
netsnmp
.
Varbind
(
xupsInputWatts
)
,
**
args
)
xupsInputVoltage
=
snmp
Walk
(
xupsInputVoltage
)
xupsInputCurrent
=
snmp
Walk
(
xupsInputCurrent
)
xupsInputWatts
=
snmp
Walk
(
xupsInputWatts
)
# Dynamic output variables
xupsOutputVoltage
=
net
snmp
.
snmpwalk
(
netsnmp
.
Varbind
(
xupsOutputVoltage
)
,
**
args
)
xupsOutputCurrent
=
net
snmp
.
snmpwalk
(
netsnmp
.
Varbind
(
xupsOutputCurrent
)
,
**
args
)
xupsOutputWatts
=
net
snmp
.
snmpwalk
(
netsnmp
.
Varbind
(
xupsOutputWatts
)
,
**
args
)
xupsOutputVoltage
=
snmp
Walk
(
xupsOutputVoltage
)
xupsOutputCurrent
=
snmp
Walk
(
xupsOutputCurrent
)
xupsOutputWatts
=
snmp
Walk
(
xupsOutputWatts
)
xupsOutputFrequency
=
int
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsOutputFrequency
)
,
**
args
)[
0
]
)
/
10
xupsOutputLoad
=
float
(
net
snmp
.
snmpget
(
netsnmp
.
Varbind
(
xupsOutputLoad
)
,
**
args
)[
0
]
)
xupsOutputFrequency
=
int
(
snmp
Get
(
xupsOutputFrequency
))
/
10
xupsOutputLoad
=
float
(
snmp
Get
(
xupsOutputLoad
))
# If we can't get an ABM reading, fallback to normal batter status (less accurate)
if
(
xupsBatteryAbmStatus
!=
5
and
xupsBatteryAbmStatus
!=
6
):
...
...
@@ -192,8 +206,12 @@ if (xupsOutputSource == 4 or xupsOutputSource == 11):
OUTPUT_TEXT
+=
"
Capacity:
"
+
str
(
xupsBatCapacity
)
+
"
%
"
OUTPUT_TEXT
+=
"
Load:
"
+
str
(
xupsOutputLoad
)
+
"
%
"
OUTPUT_TEXT
+=
"
Runtime:
"
+
str
(
xupsBatTimeRemaining
/
60
)
+
"
m
"
OUTPUT_TEXT
+=
"
Batteries Last Replaced:
"
+
xupsBatteryLastReplacedDate
OUTPUT_TEXT
+=
"
Runtime:
"
+
str
(
round
(
xupsBatTimeRemaining
/
60
,
1
))
+
"
m
"
if
xupsBatteryLastReplacedDate
==
"
None
"
:
OUTPUT_TEXT
+=
"
Batteries Last Replaced: N/A
"
else
:
OUTPUT_TEXT
+=
"
Batteries Last Replaced:
"
+
xupsBatteryLastReplacedDate
if
temperatureOutput
:
OUTPUT_TEXT
+=
"
Temperature:
"
+
str
(
envTemperature
)
+
"
C
"
...
...
@@ -213,18 +231,18 @@ PERFDATA += " xupsOutputFrequency=" + str(xupsOutputFrequency)
PERFDATA
+=
"
xupsOutputLoad=
"
+
str
(
xupsOutputLoad
)
for
phase
in
xupsInputPhase
:
PERFDATA
+=
"
xupsInputVoltage_Phase-
"
+
phase
+
"
=
"
+
str
(
xupsInputVoltage
[
int
(
phase
)
-
1
]
)
PERFDATA
+=
"
xupsInputVoltage_Phase-
"
+
phase
.
value
+
"
=
"
+
str
(
xupsInputVoltage
[
int
(
phase
.
value
)
-
1
].
value
)
if
xupsInputCurrent
:
PERFDATA
+=
"
xupsInputCurrent_Phase-
"
+
phase
+
"
=
"
+
str
(
xupsInputCurrent
[
int
(
phase
)
-
1
]
)
PERFDATA
+=
"
xupsInputCurrent_Phase-
"
+
phase
.
value
+
"
=
"
+
str
(
xupsInputCurrent
[
int
(
phase
.
value
)
-
1
].
value
)
if
xupsInputWatts
:
PERFDATA
+=
"
xupsInputWatts_Phase-
"
+
phase
+
"
=
"
+
str
(
xupsInputWatts
[
int
(
phase
)
-
1
]
)
PERFDATA
+=
"
xupsInputWatts_Phase-
"
+
phase
.
value
+
"
=
"
+
str
(
xupsInputWatts
[
int
(
phase
.
value
)
-
1
].
value
)
for
phase
in
xupsOutputPhase
:
PERFDATA
+=
"
xupsOutputVoltage_Phase-
"
+
phase
+
"
=
"
+
str
(
xupsOutputVoltage
[
int
(
phase
)
-
1
]
)
PERFDATA
+=
"
xupsOutputCurrent_Phase-
"
+
phase
+
"
=
"
+
str
(
xupsOutputCurrent
[
int
(
phase
)
-
1
]
)
PERFDATA
+=
"
xupsOutputWatts_Phase-
"
+
phase
+
"
=
"
+
str
(
xupsOutputWatts
[
int
(
phase
)
-
1
]
)
PERFDATA
+=
"
xupsOutputVoltage_Phase-
"
+
phase
.
value
+
"
=
"
+
str
(
xupsOutputVoltage
[
int
(
phase
.
value
)
-
1
].
value
)
PERFDATA
+=
"
xupsOutputCurrent_Phase-
"
+
phase
.
value
+
"
=
"
+
str
(
xupsOutputCurrent
[
int
(
phase
.
value
)
-
1
].
value
)
PERFDATA
+=
"
xupsOutputWatts_Phase-
"
+
phase
.
value
+
"
=
"
+
str
(
xupsOutputWatts
[
int
(
phase
.
value
)
-
1
].
value
)
PERFDATA
+=
"
xupsBatteryAbmStatus=
"
+
str
(
xupsBatteryAbmStatus
)
PERFDATA
+=
"
xupsBatteryStatus=
"
+
str
(
xupsBatteryStatus
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment