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
cb92b26d
Commit
cb92b26d
authored
6 years ago
by
Robert Latta
Browse files
Options
Downloads
Patches
Plain Diff
Added alarmsdb interface check implementation and route
parent
10ad9426
Branches
Branches containing commit
Tags
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
+57
-12
57 additions, 12 deletions
inventory_provider/alarmsdb.py
inventory_provider/routes/alarmsdb.py
+8
-5
8 additions, 5 deletions
inventory_provider/routes/alarmsdb.py
with
65 additions
and
17 deletions
inventory_provider/alarmsdb.py
+
57
−
12
View file @
cb92b26d
import
contextlib
import
logging
import
mysql.connector
from
inventory_provider.constants
import
DATABASE_LOGGER_NAME
@contextlib.contextmanager
def
connection
(
alarmsdb
):
...
...
@@ -32,12 +28,61 @@ def cursor(cnx):
csr
.
close
()
def
_db_test
(
db
,
router
):
database_logger
=
logging
.
getLogger
(
DATABASE_LOGGER_NAME
)
def
get_last_known_infinera_interface_status
(
db
,
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
cursor
(
db
)
as
crs
:
crs
.
execute
(
query
,
(
search_string
,))
result
=
crs
.
fetchone
()
if
not
result
:
return
"
unknown
"
elif
result
[
0
]
==
"
Raised
"
:
return
"
down
"
else
:
return
"
up
"
def
get_last_known_coriant_interface_status
(
db
,
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
cursor
(
db
)
as
crs
:
database_logger
.
debug
(
"
_db_test: %r
"
%
router
)
query
=
"
SELECT absid FROM routers WHERE hostname = %s
"
crs
.
execute
(
query
,
(
router
[
'
hostname
'
],))
for
(
absid
,)
in
crs
:
database_logger
.
debug
(
"
absid: %r
"
%
absid
)
yield
absid
crs
.
execute
(
query
,
(
equipment
,
interface
+
"
-%
"
))
result
=
crs
.
fetchone
()
if
not
result
:
return
"
unknown
"
elif
result
[
0
]
==
"
Raised
"
:
return
"
down
"
else
:
return
"
up
"
def
get_last_known_juniper_link_interface_status
(
db
,
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
cursor
(
db
)
as
crs
:
crs
.
execute
(
query
,
(
'
lo0.
'
+
equipment
,
interface
))
result
=
crs
.
fetchone
()
if
not
result
:
return
"
unknown
"
elif
result
[
0
]
==
0
:
return
"
down
"
else
:
return
"
up
"
def
get_last_known_interface_status
(
db
,
equipment
,
interface
):
result
=
get_last_known_infinera_interface_status
(
db
,
equipment
,
interface
)
if
result
==
"
unknown
"
:
result
=
get_last_known_coriant_interface_status
(
db
,
equipment
,
interface
)
if
result
==
"
unknown
"
:
result
=
get_last_known_juniper_link_interface_status
(
db
,
equipment
,
interface
)
return
result
This diff is collapsed.
Click to expand it.
inventory_provider/routes/alarmsdb.py
+
8
−
5
View file @
cb92b26d
...
...
@@ -26,16 +26,19 @@ def require_accepts_json(f):
return
decorated_function
@routes.route
(
"
/
test
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@routes.route
(
"
/
interface-status
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@require_accepts_json
def
alarmsdb_test
():
def
get_interface_status
():
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
result
=
{}
equipment
=
request
.
args
.
get
(
"
equipment
"
)
interface
=
request
.
args
.
get
(
"
interface
"
)
with
alarmsdb
.
connection
(
config
[
'
alarms-db
'
])
as
db
:
for
r
in
config
[
'
routers
'
]:
result
[
r
[
'
hostname
'
]]
=
list
(
alarmsdb
.
_db_test
(
db
,
r
))
result
=
{
"
status
"
:
alarmsdb
.
get_last_known_interface_status
(
db
,
equipment
,
interface
)}
print
(
result
)
return
Response
(
json
.
dumps
(
result
),
mimetype
=
"
application/json
"
)
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