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
20cd977d
Commit
20cd977d
authored
2 years ago
by
rick.mollard
Browse files
Options
Downloads
Patches
Plain Diff
added output file
parent
c3a8f4f6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
highTransitions.py
+10
-5
10 additions, 5 deletions
highTransitions.py
with
10 additions
and
5 deletions
highTransitions.py
+
10
−
5
View file @
20cd977d
...
...
@@ -32,13 +32,16 @@ Ausername = input()
print
(
"
Enter Password:
"
)
Apassword
=
getpass
.
getpass
()
creds
=
{
"
username
"
:
{
Ausername
},
"
password
"
:
{
Apassword
}}
file1
=
open
(
"
highTransitions.txt
"
,
"
w
"
)
for
selectIP
in
file
:
ip_add
=
selectIP
hostname
=
socket
.
getfqdn
(
ip_add
)
print
(
f
"
Login from:
{
hostname
}
{
ip_add
}
"
)
file1
.
writelines
(
f
"
Login from:
{
hostname
}
{
ip_add
}
\n
"
)
session
=
requests
.
session
()
# create sessions object
def
get_logs
(
self
):
try
:
...
...
@@ -72,17 +75,16 @@ for selectIP in file:
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]
lsplit_lldp
=
lldpModel
.
split
(
"'
chassis_description
'
:
'"
,
1
)[
1
]
final_lldp
=
lsplit_lldp
.
split
(
"'
,
"
,
1
)[
0
]
count
+=
1
#print(final_lldp)
print
(
f
"
Port:
{
Switch
}
/1/
{
SwitchPort
}
{
str_LinkTransitions
}
---
{
final_lldp
}
"
)
file1
.
write
(
f
"
Port:
{
Switch
}
/1/
{
SwitchPort
}
{
str_LinkTransitions
}
\n
"
)
final_lldp
=
"
No LLDP Info
"
# Default value if no lldp info is retreived
SwitchPort
+=
1
Switch
+=
1
SwitchPort
=
1
...
...
@@ -97,7 +99,8 @@ for selectIP in file:
LinkTransitions
=
re
.
findall
(
r
'
\d+
'
,
f
"
{
get_log
.
json
()
}
"
)
str_LinkTransitions
=
str
(
LinkTransitions
[
0
])
if
transitions
<=
int
(
str_LinkTransitions
):
print
(
f
"
Port:
{
Switch
}
/1/
{
SwitchPort
}
{
str_LinkTransitions
}
"
)
print
(
f
"
Port:
{
Switch
}
/1/
{
SwitchPort
}
{
str_LinkTransitions
}
---
{
final_lldp
}
"
)
file1
.
write
(
f
"
Port:
{
Switch
}
/1/
{
SwitchPort
}
{
str_LinkTransitions
}
\n
"
)
SwitchPort
+=
1
Switch
+=
1
SwitchPort
=
1
...
...
@@ -107,10 +110,12 @@ for selectIP in file:
logout
=
session
.
post
(
f
"
https://
{
self
}
/rest/v1/logout
"
)
print
(
f
"
Logout from:
{
hostname
}
{
ip_add
}
"
)
file1
.
write
(
f
"
Logout from:
{
hostname
}
{
ip_add
}
\n
"
)
except
requests
.
exceptions
.
RequestException
as
e
:
print
(
"
Switch is not responding----->
"
+
ip_add
)
print
(
"
Switch is not responding----->
"
+
ip_add
)
print
(
"
Switch is not responding----->
"
+
ip_add
)
print
(
"
Switch is not responding----->
"
+
ip_add
)
file1
.
write
(
"
Switch is not responding----->
"
+
ip_add
+
"
\n
"
)
...
...
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