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
2e509dde
Commit
2e509dde
authored
3 years ago
by
Erik Reid
Browse files
Options
Downloads
Plain Diff
Finished feature DBOARD3-483-add-dashboards-to-interfaces.
parents
ad924884
6ba7be1b
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/routes/poller.py
+103
-3
103 additions, 3 deletions
inventory_provider/routes/poller.py
test/test_general_poller_routes.py
+17
-0
17 additions, 0 deletions
test/test_general_poller_routes.py
with
120 additions
and
3 deletions
inventory_provider/routes/poller.py
+
103
−
3
View file @
2e509dde
...
...
@@ -49,6 +49,7 @@ These endpoints are intended for use by BRIAN.
"""
from
enum
import
Enum
,
auto
import
json
import
logging
import
re
...
...
@@ -68,6 +69,32 @@ routes = Blueprint('poller-support-routes', __name__)
Gb
=
1
<<
30
class
BRIAN_DASHBOARDS
(
Enum
):
CLS
=
auto
()
RE_PEER
=
auto
()
RE_CUST
=
auto
()
GEANTOPEN
=
auto
()
GCS
=
auto
()
L2_CIRCUIT
=
auto
()
LHCONE_PEER
=
auto
()
LHCONE_CUST
=
auto
()
MDVPN_CUSTOMERS
=
auto
()
INFRASTRUCTURE_BACKBONE
=
auto
()
IAS_PRIVATE
=
auto
()
IAS_PUBLIC
=
auto
()
IAS_CUSTOMER
=
auto
()
IAS_UPSTREAM
=
auto
()
GWS_PHY_UPSTREAM
=
auto
()
# aggregate dashboards
CLS_PEERS
=
auto
()
IAS_PEERS
=
auto
()
GWS_UPSTREAMS
=
auto
()
LHCONE
=
auto
()
CAE1
=
auto
()
INTERFACE_LIST_SCHEMA
=
{
'
$schema
'
:
'
http://json-schema.org/draft-07/schema#
'
,
...
...
@@ -104,12 +131,16 @@ INTERFACE_LIST_SCHEMA = {
'
circuits
'
:
{
'
type
'
:
'
array
'
,
'
items
'
:
{
'
$ref
'
:
'
#/definitions/service
'
}
},
'
dashboards
'
:
{
'
type
'
:
'
array
'
,
'
items
'
:
{
'
enum
'
:
[
d
.
name
for
d
in
list
(
BRIAN_DASHBOARDS
)]}
}
},
'
required
'
:
[
'
router
'
,
'
name
'
,
'
description
'
,
'
snmp-index
'
,
'
bundle
'
,
'
bundle-parents
'
,
'
circuits
'
],
'
circuits
'
,
'
dashboards
'
],
'
additionalProperties
'
:
False
},
},
...
...
@@ -296,6 +327,70 @@ def after_request(resp):
return
common
.
after_request
(
resp
)
def
_get_dashboards
(
interface
):
router
=
interface
.
get
(
'
router
'
,
''
).
lower
()
ifc_name
=
interface
.
get
(
'
name
'
,
''
)
description
=
interface
.
get
(
'
description
'
,
''
).
strip
()
if
'
SRV_CLS
'
in
description
:
yield
BRIAN_DASHBOARDS
.
CLS
if
'
SRV_CLS PRIVATE
'
in
description
:
yield
BRIAN_DASHBOARDS
.
CLS_PEERS
if
'
SRV_IAS PUBLIC
'
in
description
:
yield
BRIAN_DASHBOARDS
.
IAS_PUBLIC
yield
BRIAN_DASHBOARDS
.
IAS_PEERS
if
'
SRV_IAS PRIVATE
'
in
description
:
yield
BRIAN_DASHBOARDS
.
IAS_PRIVATE
yield
BRIAN_DASHBOARDS
.
IAS_PEERS
if
'
SRV_IAS CUSTOMER
'
in
description
:
yield
BRIAN_DASHBOARDS
.
IAS_CUSTOMER
if
'
SRV_IAS UPSTREAM
'
in
description
:
yield
BRIAN_DASHBOARDS
.
IAS_UPSTREAM
if
'
SRV_GLOBAL RE_INTERCONNECT
'
in
description
:
yield
BRIAN_DASHBOARDS
.
RE_PEER
if
re
.
match
(
'
(PHY|LAG|SRV_GLOBAL) CUSTOMER
'
,
description
):
yield
BRIAN_DASHBOARDS
.
RE_CUST
if
re
.
match
(
'
^SRV_GCS
'
,
description
):
yield
BRIAN_DASHBOARDS
.
GCS
if
'
GEANTOPEN
'
in
description
:
yield
BRIAN_DASHBOARDS
.
GEANTOPEN
if
'
SRV_L2CIRCUIT
'
in
description
:
yield
BRIAN_DASHBOARDS
.
L2_CIRCUIT
if
'
LHCONE
'
in
description
:
if
'
SRV_L3VPN RE
'
in
description
:
yield
BRIAN_DASHBOARDS
.
LHCONE_PEER
if
'
SRV_L3VPN CUSTOMER
'
in
description
:
yield
BRIAN_DASHBOARDS
.
LHCONE_CUST
if
re
.
match
(
'
SRV_L3VPN (CUSTOMER|RE_INTERCONNECT)
'
,
description
):
yield
BRIAN_DASHBOARDS
.
LHCONE
if
re
.
match
(
'
^SRV_MDVPN CUSTOMER
'
,
description
):
yield
BRIAN_DASHBOARDS
.
MDVPN_CUSTOMERS
if
'
LAG
'
in
description
and
\
re
.
match
(
'
(SRV_GLOBAL|LAG|PHY) INFRASTRUCTURE BACKBONE
'
,
description
):
yield
BRIAN_DASHBOARDS
.
INFRASTRUCTURE_BACKBONE
if
router
==
'
mx1.lon.uk.geant.net
'
\
and
re
.
match
(
r
'
^ae12(\.\d+|$)$
'
,
ifc_name
):
yield
BRIAN_DASHBOARDS
.
CAE1
if
re
.
match
(
'
^PHY UPSTREAM
'
,
description
):
yield
BRIAN_DASHBOARDS
.
GWS_PHY_UPSTREAM
def
_add_dashboards
(
interfaces
):
"""
generator that dashboards to each interfaces.
:param interfaces: result of _load_interfaces
:return: generator with `dashboards` populated in each element
"""
for
ifc
in
interfaces
:
dashboards
=
_get_dashboards
(
ifc
)
ifc
[
'
dashboards
'
]
=
sorted
(
list
(
d
.
name
for
d
in
dashboards
))
yield
ifc
def
_load_interface_bundles
(
hostname
=
None
):
result
=
dict
()
...
...
@@ -476,15 +571,20 @@ def _load_interfaces_to_poll(hostname=None):
:return: generator yielding interface elements
"""
basic_interfaces
=
_load_interfaces
(
hostname
)
# basic_interfaces = list(basic_interfaces)
with_bundles
=
_add_bundle_parents
(
basic_interfaces
,
hostname
)
with_circuits
=
_add_circuits
(
with_bundles
,
hostname
)
# with_circuits = list(with_circuits)
with_snmp
=
_add_snmp_indexes
(
with_circuits
,
hostname
)
# with_snmp = list(with_snmp)
# only return interfaces that can be polled
def
_has_snmp_index
(
ifc
):
return
'
snmp-index
'
in
ifc
# only return interfaces that can be polled
return
filter
(
_has_snmp_index
,
with_snmp
)
to_poll
=
filter
(
_has_snmp_index
,
with_snmp
)
return
_add_dashboards
(
to_poll
)
@routes.route
(
"
/interfaces
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
...
This diff is collapsed.
Click to expand it.
test/test_general_poller_routes.py
+
17
−
0
View file @
2e509dde
...
...
@@ -215,3 +215,20 @@ def test_dcu_oid_values(ifIndex, expected_oid):
def
test_fw_counter_bytes_oid_values
(
customer
,
interface_name
,
expected_oid
):
assert
poller
.
_jnx_fw_counter_bytes_oid
(
customer
,
interface_name
)
==
expected_oid
@pytest.mark.parametrize
(
'
description,expected_dashboards
'
,
[
(
'
SRV_IAS CUSTOMER JISC #JISC-AP1-IAS IASPS | ASN786
'
,
[
'
IAS_CUSTOMER
'
]),
(
'
SRV_L2CIRCUIT CUSTOMER JISC JISC #DUB-LON-NRENBBEXT-JANET-13015 | backup for niran
'
,
# noqa: E501
[
'
L2_CIRCUIT
'
])
])
def
test_interface_dashboard_mapping
(
description
,
expected_dashboards
):
interface
=
{
'
router
'
:
''
,
'
name
'
:
''
,
'
description
'
:
description
}
dashboards
=
poller
.
_get_dashboards
(
interface
)
dashboards
=
[
d
.
name
for
d
in
dashboards
]
assert
set
(
list
(
dashboards
))
==
set
(
expected_dashboards
)
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