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
fdf7ca09
Commit
fdf7ca09
authored
6 years ago
by
Robert Latta
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/trap-inventory-response-api' into develop
parents
c6f200a9
40a82881
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+14
-0
14 additions, 0 deletions
README.md
inventory_provider/routes/classifier.py
+40
-0
40 additions, 0 deletions
inventory_provider/routes/classifier.py
test/test_classifier_routes.py
+36
-0
36 additions, 0 deletions
test/test_classifier_routes.py
with
90 additions
and
0 deletions
README.md
+
14
−
0
View file @
fdf7ca09
...
@@ -269,4 +269,18 @@ Any non-empty responses are JSON formatted messages.
...
@@ -269,4 +269,18 @@ Any non-empty responses are JSON formatted messages.
"type"
:
"array"
,
"type"
:
"array"
,
"items"
:
{
"type"
:
"string"
}
"items"
:
{
"type"
:
"string"
}
}
}
```
*
/classifier/
*`type`*
/
*`source-equipment`*
/
`*source-interface*`
The source-equipment is the equipment that causes the trap, not the NMS that
sends it.
The response will be an object containing the metadata
```
json
{
"$schema"
:
"http://json-schema.org/draft-07/schema#"
,
"type"
:
"object"
}
```
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.
inventory_provider/routes/classifier.py
+
40
−
0
View file @
fdf7ca09
...
@@ -69,3 +69,43 @@ def juniper_addresses():
...
@@ -69,3 +69,43 @@ def juniper_addresses():
servers
=
json
.
loads
(
servers
.
decode
(
'
utf-8
'
))
servers
=
json
.
loads
(
servers
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
servers
,
backend_data_schema
)
jsonschema
.
validate
(
servers
,
backend_data_schema
)
return
jsonify
([
s
[
'
ip_address
'
]
for
s
in
servers
])
return
jsonify
([
s
[
'
ip_address
'
]
for
s
in
servers
])
@routes.route
(
"
/trap-metadata/<trap_type>/<source_equipment>/<path:interface>
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
@require_accepts_json
def
get_trap_metadata
(
trap_type
,
source_equipment
,
interface
):
# todo - Move this to config
interface_info_key
=
"
interface_services
"
r
=
db
.
get_redis
()
# todo - Change this to a call to the yet-to-be-created one source of all
# relevant information
# This could be different calls dependant on vendor, in which case we may
# need to check the trap type, or it could be a case of a key check for
# each possible data source
interface_info
=
r
.
hget
(
interface_info_key
,
"
{}::{}
"
.
format
(
source_equipment
,
interface
))
if
not
interface_info
:
return
Response
(
response
=
"
no available info for {} {}
"
.
format
(
source_equipment
,
interface
),
status
=
404
,
mimetype
=
"
text/html
"
)
interface_info
=
json
.
loads
(
interface_info
.
decode
(
'
utf-8
'
))
# todo - refactor once structure of new source is decided, currently this
# is just a list of services
vendor
=
interface_info
[
0
][
'
manufacturer
'
]
hostname
=
interface_info
[
0
][
'
equipment
'
]
result
=
{
"
vendor
"
:
vendor
,
"
equipment-name
"
:
hostname
,
"
interface-name
"
:
interface
,
"
services
"
:
interface_info
,
"
type
"
:
trap_type
}
return
jsonify
(
result
)
This diff is collapsed.
Click to expand it.
test/test_classifier_routes.py
+
36
−
0
View file @
fdf7ca09
...
@@ -73,3 +73,39 @@ def test_juniper_addresses(mocker, client):
...
@@ -73,3 +73,39 @@ def test_juniper_addresses(mocker, client):
jsonschema
.
validate
(
response_data
,
response_schema
)
jsonschema
.
validate
(
response_data
,
response_schema
)
assert
len
(
response_data
)
==
len
(
test_data
)
assert
len
(
response_data
)
==
len
(
test_data
)
assert
set
([
x
[
'
ip_address
'
]
for
x
in
test_data
])
==
set
(
response_data
)
assert
set
([
x
[
'
ip_address
'
]
for
x
in
test_data
])
==
set
(
response_data
)
def
test_trap_metadata
(
mocker
,
client
):
test_data
=
[
{
"
equipment
"
:
"
test-equipment
"
,
"
manufacturer
"
:
"
test-manufacturer
"
,
"
vendor
"
:
"
test-vendor
"
,
"
absid
"
:
"
1234
"
,
"
name
"
:
"
test-service_1
"
},
{
"
equipment
"
:
"
test-equipment
"
,
"
manufacturer
"
:
"
test-manufacturer
"
,
"
vendor
"
:
"
test-vendor
"
,
"
absid
"
:
"
2345
"
,
"
name
"
:
"
test-service_2
"
}
]
mocked_redis
=
mocker
.
patch
(
"
inventory_provider.routes.classifier.db.get_redis
"
)
mocked_redis
.
return_value
.
hget
.
return_value
=
json
.
dumps
(
test_data
)
\
.
encode
(
"
utf-8
"
)
response_schema
=
{
"
$schema
"
:
"
http://json-schema.org/draft-07/schema#
"
,
"
type
"
:
"
object
"
}
rv
=
client
.
get
(
'
/classifier/trap-metadata/BGP/dummy-equipment/xe-2/3/1
'
,
headers
=
DEFAULT_REQUEST_HEADERS
)
assert
rv
.
status_code
==
200
assert
rv
.
is_json
response_data
=
json
.
loads
(
rv
.
data
.
decode
(
'
utf-8
'
))
jsonschema
.
validate
(
response_data
,
response_schema
)
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