Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inventory-provider
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
geant-swd
dashboardv3
inventory-provider
Commits
c7af7369
Commit
c7af7369
authored
6 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
Added addiotional route and implementation for getting interface status from cache
parent
40869a66
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
inventory_provider/alarmsdb.py
+13
-16
13 additions, 16 deletions
inventory_provider/alarmsdb.py
inventory_provider/routes/data.py
+18
-2
18 additions, 2 deletions
inventory_provider/routes/data.py
with
31 additions
and
18 deletions
inventory_provider/alarmsdb.py
+
13
−
16
View file @
c7af7369
from
inventory_provider
import
db
def
get_last_known_infinera_interface_status
(
c
onnection
,
equipment
,
interface
):
def
get_last_known_infinera_interface_status
(
c
rs
,
equipment
,
interface
):
query
=
"
SELECT status FROM infinera_alarms
"
\
"
WHERE
"
\
"
CONCAT(ne_name,
'
-
'
, REPLACE(object_name,
'
T
'
,
''
)) = %s
"
\
"
ORDER BY ne_init_time DESC, ne_clear_time DESC LIMIT 1
"
search_string
=
equipment
+
"
-
"
+
interface
with
db
.
cursor
(
connection
)
as
crs
:
crs
.
execute
(
query
,
(
search_string
,))
result
=
crs
.
fetchone
()
crs
.
execute
(
query
,
(
search_string
,))
result
=
crs
.
fetchone
()
if
not
result
:
return
"
unknown
"
elif
result
[
0
]
==
"
Raised
"
:
...
...
@@ -18,13 +17,12 @@ def get_last_known_infinera_interface_status(connection, equipment, interface):
return
"
up
"
def
get_last_known_coriant_interface_status
(
c
onnection
,
equipment
,
interface
):
def
get_last_known_coriant_interface_status
(
c
rs
,
equipment
,
interface
):
query
=
"
SELECT status FROM coriant_alarms
"
\
"
WHERE ne_id_name = %s AND entity_string LIKE %s
"
\
"
ORDER BY last_event_time DESC LIMIT 1
"
with
db
.
cursor
(
connection
)
as
crs
:
crs
.
execute
(
query
,
(
equipment
,
interface
+
"
-%
"
))
result
=
crs
.
fetchone
()
crs
.
execute
(
query
,
(
equipment
,
interface
+
"
-%
"
))
result
=
crs
.
fetchone
()
if
not
result
:
return
"
unknown
"
elif
result
[
0
]
==
"
Raised
"
:
...
...
@@ -34,14 +32,13 @@ def get_last_known_coriant_interface_status(connection, equipment, interface):
def
get_last_known_juniper_link_interface_status
(
c
onnection
,
equipment
,
interface
):
c
rs
,
equipment
,
interface
):
query
=
"
SELECT IF(link_admin_status =
'
up
'"
\
"
AND link_oper_status =
'
up
'
, 1, 0) AS up FROM juniper_alarms
"
\
"
WHERE equipment_name = %s AND link_interface_name = %s
"
\
"
ORDER BY alarm_id DESC LIMIT 1
"
with
db
.
cursor
(
connection
)
as
crs
:
crs
.
execute
(
query
,
(
'
lo0.
'
+
equipment
,
interface
))
result
=
crs
.
fetchone
()
crs
.
execute
(
query
,
(
'
lo0.
'
+
equipment
,
interface
))
result
=
crs
.
fetchone
()
if
not
result
:
return
"
unknown
"
elif
result
[
0
]
==
0
:
...
...
@@ -50,15 +47,15 @@ def get_last_known_juniper_link_interface_status(
return
"
up
"
def
get_last_known_interface_status
(
c
onnection
,
equipment
,
interface
):
def
get_last_known_interface_status
(
c
rs
,
equipment
,
interface
):
result
=
get_last_known_infinera_interface_status
(
c
onnection
,
equipment
,
interface
)
c
rs
,
equipment
,
interface
)
if
result
==
"
unknown
"
:
result
=
get_last_known_coriant_interface_status
(
c
onnection
,
equipment
,
interface
)
c
rs
,
equipment
,
interface
)
if
result
==
"
unknown
"
:
result
=
get_last_known_juniper_link_interface_status
(
c
onnection
,
equipment
,
interface
)
c
rs
,
equipment
,
interface
)
return
result
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/routes/data.py
+
18
−
2
View file @
c7af7369
...
...
@@ -2,11 +2,12 @@ import functools
import
json
import
pkg_resources
from
flask
import
Blueprint
,
request
,
Response
,
current_app
from
flask
import
Blueprint
,
jsonify
,
request
,
Response
,
current_app
from
lxml
import
etree
import
redis
from
inventory_provider
import
juniper
from
inventory_provider
import
db
,
juniper
from
inventory_provider.storage
import
external_inventory
routes
=
Blueprint
(
"
inventory-data-query-routes
"
,
__name__
)
...
...
@@ -162,3 +163,18 @@ def bgp_configs(hostname):
return
Response
(
json
.
dumps
(
routes
),
mimetype
=
"
application/json
"
)
@routes.route
(
"
/interfaces/status/<hostname>/<path:interface>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@require_accepts_json
def
interface_statuses
(
hostname
,
interface
):
r
=
db
.
get_redis
()
result
=
r
.
hget
(
external_inventory
.
interface_status_key
,
"
{}::{}
"
.
format
(
hostname
,
interface
))
if
not
result
:
return
Response
(
response
=
"
no available info for {} {}
"
.
format
(
hostname
,
interface
),
status
=
404
,
mimetype
=
"
text/html
"
)
return
jsonify
({
"
status
"
:
result
.
decode
(
'
utf-8
'
)})
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