Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
JR Dalrymple
/
pf_interface_usage
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
09ad163a
authored
Nov 02, 2015
by
JR Dalrymple
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Works in beta - going to monitor some GSE LLC interfaces with it
parent
65fa1686
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
4 deletions
+31
-4
check_snmp_usage.py
+31
-4
No files found.
check_snmp_usage.py
View file @
09ad163a
...
...
@@ -32,11 +32,12 @@ import subprocess
import
datetime
host
=
''
debug
=
0
communityString
=
'public'
OIDDateTime
=
'.1.3.6.1.2.1.25.1.2.0'
OIDIfDescr
=
'.1.3.6.1.2.1.2.2.1.2'
OIDIfInBytes
=
'.1.3.6.1.2.1.2.2.1.10.
1.
'
OIDIfOutBytes
=
'.1.3.6.1.2.1.2.2.1.16.
1.
'
OIDIfInBytes
=
'.1.3.6.1.2.1.2.2.1.10.'
OIDIfOutBytes
=
'.1.3.6.1.2.1.2.2.1.16.'
unitMultipliers
=
{
'b'
:
1
,
'B'
:
1
,
...
...
@@ -56,7 +57,7 @@ limitMatch = re.compile(r"([0-9]+)([bBkKmMgGtT]{0,1})")
def
usage
():
print
(
'Usage: check_snmp_usage.py -H hostname -i interface -b bandwidth limit (bytes) -c community string
\n
'
)
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'H:i:b:c'
)
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'H:i:b:c
d
'
)
except
getopt
.
GetoptError
as
err
:
print
(
err
)
usage
()
...
...
@@ -71,6 +72,8 @@ for opt, arg in opts:
bytesLimit
=
arg
elif
opt
in
(
'-c'
):
communityString
=
arg
elif
opt
in
(
'-d'
):
debug
=
1
else
:
usage
()
sys
.
exit
(
3
)
...
...
@@ -246,4 +249,28 @@ monthComplete = ( float(secondsIntoMonth.total_seconds()) / float(secondsInMonth
totalDataUsed
=
int
(
inBytesTotal
)
+
int
(
outBytesTotal
)
percentageDataUsed
=
(
float
(
totalDataUsed
)
/
float
(
bytesLimit
)
)
*
100
print
percentageDataUsed
# Generate perfdata:
perfdata
=
'|
\'
BytesInRate
\'
='
+
str
(
inBytesPerSec
)
+
'bytes/sec;;;;
\'
BytesOutRate
\'
='
+
str
(
outBytesPerSec
)
+
'bytes/sec;;;;'
# Calculate warning/critical
if
totalDataUsed
>
bytesLimit
:
print
(
'CRITICAL - You have exceeded your alloted data usage for this period'
+
perfdata
)
print
(
'You are alloted '
+
str
(
bytesLimit
)
+
' bytes for the month but have already used '
+
str
(
totalDataUsed
)
+
' bytes.'
)
sys
.
exit
(
2
)
elif
percentageDataUsed
>
monthComplete
:
print
(
'WARNING - You are using data at a rate that will cause you to exceed usage allotment for this period'
+
perfdata
)
print
(
'The month is '
+
str
(
round
(
monthComplete
,
2
))
+
'
%
complete.'
)
print
(
'The data allotment on interface '
+
interface
+
' is '
+
str
(
round
(
percentageDataUsed
,
2
))
+
'
%
used.'
)
sys
.
exit
(
1
)
else
:
print
(
'OK - You will not use all of your alloted data for this period at the current rate'
+
perfdata
)
sys
.
exit
(
0
)
if
debug
==
1
:
print
(
'The month is '
+
str
(
round
(
monthComplete
,
2
))
+
'
%
complete.'
)
print
(
'The data allotment on interface '
+
interface
+
' is '
+
str
(
round
(
percentageDataUsed
,
2
))
+
'
%
used.'
)
print
(
'The current incoming rate is '
+
str
(
inBytesPerSec
)
+
' bytes/second.'
)
print
(
'The current outgoing rate is '
+
str
(
outBytesPerSec
)
+
' bytes/second.'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment