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
857b910a
authored
Nov 02, 2015
by
JR Dalrymple
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unit conversions are working for the usage limit argument
parent
796dde7c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
2 deletions
+26
-2
check_snmp_usage.py
+26
-2
No files found.
check_snmp_usage.py
View file @
857b910a
...
@@ -38,6 +38,18 @@ OIDIfDescr = '.1.3.6.1.2.1.2.2.1.2'
...
@@ -38,6 +38,18 @@ OIDIfDescr = '.1.3.6.1.2.1.2.2.1.2'
OIDIfInBytes
=
'.1.3.6.1.2.1.2.2.1.10.1.'
OIDIfInBytes
=
'.1.3.6.1.2.1.2.2.1.10.1.'
OIDIfOutBytes
=
'.1.3.6.1.2.1.2.2.1.16.1.'
OIDIfOutBytes
=
'.1.3.6.1.2.1.2.2.1.16.1.'
unitMultipliers
=
{
'k'
:
1024
,
'K'
:
1024
,
'm'
:
1024
*
1024
,
'M'
:
1024
*
1024
,
'g'
:
1024
*
1024
*
1024
,
'G'
:
1024
*
1024
*
1024
,
't'
:
1024
*
1024
*
1024
*
1024
,
'T'
:
1024
*
1024
*
1024
*
1024
,
}
limitMatch
=
re
.
compile
(
r"([0-9]+)([kKmMgGtT]{0,1})"
)
#USAGE
#USAGE
def
usage
():
def
usage
():
print
(
'Usage: check_snmp_usage.py -H hostname -i interface -b bandwidth limit (bytes) -c community string
\n
'
)
print
(
'Usage: check_snmp_usage.py -H hostname -i interface -b bandwidth limit (bytes) -c community string
\n
'
)
...
@@ -61,10 +73,22 @@ for opt, arg in opts:
...
@@ -61,10 +73,22 @@ for opt, arg in opts:
usage
()
usage
()
sys
.
exit
(
3
)
sys
.
exit
(
3
)
# Argument processing
if
not
'host'
in
locals
():
if
not
'host'
in
locals
():
print
(
'No host specified'
)
print
(
'No host specified'
)
sys
.
exit
(
3
)
sys
.
exit
(
3
)
if
not
'bytesLimit'
in
locals
():
bytesLimit
=
0
if
not
limitMatch
.
match
(
bytesLimit
):
print
(
'Could not validate limit argument'
)
else
:
scalar
=
limitMatch
.
search
(
bytesLimit
)
.
group
(
1
)
multiplier
=
limitMatch
.
search
(
bytesLimit
)
.
group
(
2
)
if
multiplier
:
bytesLimit
=
int
(
scalar
)
*
int
(
unitMultipliers
[
multiplier
])
# Find snmpwalk and snmpget
# Find snmpwalk and snmpget
sp
=
subprocess
.
Popen
([
'which'
,
'snmpget'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
sp
=
subprocess
.
Popen
([
'which'
,
'snmpget'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
...
@@ -219,5 +243,5 @@ monthComplete = ( float(secondsIntoMonth.total_seconds()) / float(secondsInMonth
...
@@ -219,5 +243,5 @@ monthComplete = ( float(secondsIntoMonth.total_seconds()) / float(secondsInMonth
totalDataUsed
=
int
(
inBytesTotal
)
+
int
(
outBytesTotal
)
totalDataUsed
=
int
(
inBytesTotal
)
+
int
(
outBytesTotal
)
percentageDataUsed
=
(
float
(
totalDataUsed
)
/
float
(
bytesLimit
)
)
*
100
percentageDataUsed
=
(
float
(
totalDataUsed
)
/
float
(
bytesLimit
)
)
*
100
print
(
monthComplete
)
print
(
percentageDataUsed
)
print
percentageDataUsed
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