Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rm-pythonScripts
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
Service Desk
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
network-tools
rm-pythonScripts
Commits
7c2634ca
Commit
7c2634ca
authored
2 years ago
by
rick.mollard
Browse files
Options
Downloads
Patches
Plain Diff
LLDP support
parent
79037c58
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
highTransitions.py
+45
-14
45 additions, 14 deletions
highTransitions.py
with
45 additions
and
14 deletions
highTransitions.py
+
45
−
14
View file @
7c2634ca
...
...
@@ -33,34 +33,62 @@ print("Enter Password:")
Apassword
=
getpass
.
getpass
()
creds
=
{
"
username
"
:
{
Ausername
},
"
password
"
:
{
Apassword
}}
#policyrole = "wired_l1_game_dur-3142-2"
for
selectIP
in
file
:
ip_add
=
selectIP
hostname
=
socket
.
getfqdn
(
ip_add
)
print
(
f
"
Login from:
{
hostname
}
{
ip_add
}
"
)
session
=
requests
.
session
()
# create sessions object
def
get_logs
(
self
):
try
:
# Login to API and set initial Variables
login
=
session
.
post
(
f
"
https://
{
self
}
/rest/v1/login
"
,
data
=
creds
,
verify
=
False
)
transitions
=
5
000
transitions
=
10
000
vsfMember
=
1
Switch
=
1
SwitchPort
=
1
# Check to see how many switches are in stack and convert to string
get_vsf
=
session
.
get
(
f
"
https://
{
self
}
/rest/v10.04/system/vsf_members?attributes=id&depth=2&selector=status&count=true
"
)
vsfMember
=
re
.
findall
(
r
'
\d+
'
,
f
"
{
get_vsf
.
json
()
}
"
)
str_vsfMember
=
str
(
vsfMember
[
0
])
# Check the model of the switch
get_model
=
session
.
get
(
f
"
https://
{
self
}
/rest/v10.04/system/subsystems/chassis,
{
Switch
}
?attributes=part_number_cfg&depth=4
"
)
vsfModel
=
re
.
findall
(
r
'
\d+
'
,
f
"
{
get_model
.
json
()
}
"
)
#Run Program on all switches and ports to find High link trasitions.
while
Switch
<=
int
(
str_vsfMember
[
0
]):
if
f
"
{
str
(
vsfModel
)
}
"
==
"
[
'
661
'
]
"
or
f
"
{
str
(
vsfModel
)
}
"
==
"
[
'
659
'
]
"
:
# run for all 48 port switchs
while
SwitchPort
<
49
:
get_log
=
session
.
get
(
f
"
https://
{
self
}
/rest/v10.04/system/interfaces/
{
Switch
}
%2F1%2F
{
SwitchPort
}
?attributes=link_resets&depth=2&selector=statistics
"
)
LinkTransitions
=
re
.
findall
(
r
'
\d+
'
,
f
"
{
get_log
.
json
()
}
"
)
str_LinkTransitions
=
str
(
LinkTransitions
[
0
])
if
transitions
<=
int
(
str_LinkTransitions
):
get_lldp
=
session
.
get
(
f
"
https://
{
self
}
/rest/v10.04/system/interfaces/
{
Switch
}
%2F1%2F
{
SwitchPort
}
/lldp_neighbors?attributes=neighbor_info&depth=4&selector=status&filter=
"
)
lldpModel
=
f
"
{
get_lldp
.
json
()
}
"
split_lldpModel
=
lldpModel
.
split
(
"
,
"
)
count
=
3
while
count
<
len
(
split_lldpModel
):
# This handles errors when no lldp info is found.
final_lldp
=
split_lldpModel
[
3
]
count
+=
1
print
(
f
"
Port:
{
Switch
}
/1/
{
SwitchPort
}
{
str_LinkTransitions
}
---
{
final_lldp
}
"
)
final_lldp
=
"
No LLDP Info
"
# Default value if no lldp info is retreived
SwitchPort
+=
1
Switch
+=
1
SwitchPort
=
1
get_model
=
session
.
get
(
f
"
https://
{
self
}
/rest/v10.04/system/subsystems/chassis,
{
Switch
}
?attributes=part_number_cfg&depth=4
"
)
vsfModel
=
re
.
findall
(
r
'
\d+
'
,
f
"
{
get_model
.
json
()
}
"
)
else
:
while
Switch
<=
int
(
str_vsfMember
[
0
]):
# Run for all 24 port switches
get_model
=
session
.
get
(
f
"
https://
{
self
}
/rest/v10.04/system/subsystems/chassis,
{
Switch
}
?attributes=part_number_cfg&depth=4
"
)
vsfModel
=
re
.
findall
(
r
'
\d+
'
,
f
"
{
get_model
.
json
()
}
"
)
while
SwitchPort
<
25
:
get_log
=
session
.
get
(
f
"
https://
{
self
}
/rest/v10.04/system/interfaces/
{
Switch
}
%2F1%2F
{
SwitchPort
}
?attributes=link_resets&depth=2&selector=statistics
"
)
LinkTransitions
=
re
.
findall
(
r
'
\d+
'
,
f
"
{
get_log
.
json
()
}
"
)
str_LinkTransitions
=
str
(
LinkTransitions
[
0
])
...
...
@@ -68,6 +96,9 @@ for selectIP in file:
print
(
f
"
Port:
{
Switch
}
/1/
{
SwitchPort
}
{
str_LinkTransitions
}
"
)
SwitchPort
+=
1
Switch
+=
1
SwitchPort
=
1
get_model
=
session
.
get
(
f
"
https://
{
self
}
/rest/v10.04/system/subsystems/chassis,
{
Switch
}
?attributes=part_number_cfg&depth=4
"
)
vsfModel
=
re
.
findall
(
r
'
\d+
'
,
f
"
{
get_model
.
json
()
}
"
)
logout
=
session
.
post
(
f
"
https://
{
self
}
/rest/v1/logout
"
)
...
...
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