Skip to content
Snippets Groups Projects
Commit fe5831d5 authored by Erik Reid's avatar Erik Reid
Browse files

Finished feature classifier-cache.

parents 7cab35bc 266efe7a
No related branches found
No related tags found
No related merge requests found
......@@ -426,7 +426,7 @@ Any non-empty responses are JSON formatted messages.
}
}
}
```
```
`opsdb:interface_services:<equipment name>:<interface name>`
......@@ -542,7 +542,7 @@ Any non-empty responses are JSON formatted messages.
* `opsdb:services:children:12363`
* `opsdb:services:parents:14407`
* value schema
TODO: this needs to be checked ...
TODO: this needs to be checked ...
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
......@@ -593,6 +593,7 @@ Any non-empty responses are JSON formatted messages.
* `alarmsdb:interface_status:Lab node 1:1-1/3`
* `alarmsdb:interface_status:mx1.ams.nl.geant.net:ae15.1500`
* valid values:
TODO: verify these values
* `unknown`
* `up`
* `down`
\ No newline at end of file
......@@ -39,33 +39,43 @@ def juniper_addresses():
def get_trap_metadata(source_equipment, interface):
r = common.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.get(
'opsdb:interface_services:%s:%s' % (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']
# TODO: don't copy unecessary data into response (let client do this)
result = {
"vendor": vendor,
"equipment-name": hostname,
"interface-name": interface,
"services": interface_info
}
return jsonify(result)
cache_key = 'classifier:cache:%s:%s' % (source_equipment, interface)
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
else:
# 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.get(
'opsdb:interface_services:%s:%s' % (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']
# TODO: don't copy unecessary data into response (let client do this)
result = {
"vendor": vendor,
"equipment-name": hostname,
"interface-name": interface,
"services": interface_info
}
result = json.dumps(result)
# cache this data for the next call
r.set(cache_key, result.encode('utf-8'))
return Response(result, mimetype="application/json")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment