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
8b13a7f0
Commit
8b13a7f0
authored
6 years ago
by
Erik Reid
Browse files
Options
Downloads
Patches
Plain Diff
added basic alarmsdb table cache sample
parent
ba05d954
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
inventory_provider/alarmsdb.py
+14
-0
14 additions, 0 deletions
inventory_provider/alarmsdb.py
inventory_provider/routes/jobs.py
+11
-0
11 additions, 0 deletions
inventory_provider/routes/jobs.py
inventory_provider/tasks/worker.py
+33
-0
33 additions, 0 deletions
inventory_provider/tasks/worker.py
with
58 additions
and
0 deletions
inventory_provider/alarmsdb.py
+
14
−
0
View file @
8b13a7f0
...
...
@@ -60,3 +60,17 @@ def get_last_known_interface_status(connection, equipment, interface):
result
=
get_last_known_juniper_link_interface_status
(
connection
,
equipment
,
interface
)
return
result
def
_load_juniper_servers_table
(
connection
):
with
db
.
cursor
(
connection
)
as
crs
:
crs
.
execute
(
'
select ip_address, project_name from juniper_servers
'
)
for
row
in
crs
.
fetchall
():
yield
{
'
ip_address
'
:
row
[
0
],
'
project_name
'
:
row
[
1
]
}
def
load_cache
(
connection
):
yield
"
juniper_servers
"
,
list
(
_load_juniper_servers_table
(
connection
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
inventory_provider/routes/jobs.py
+
11
−
0
View file @
8b13a7f0
...
...
@@ -38,6 +38,17 @@ def update():
return
Response
(
"
OK
"
)
@routes.route
(
"
/update-startup
"
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
startup_update
():
task_logger
=
logging
.
getLogger
(
TASK_LOGGER_NAME
)
task_logger
.
debug
(
'
launching task:
'
'
inventory_provider.tasks.worker.update_alarmsdb_cache
'
)
app
.
send_task
(
'
inventory_provider.tasks.worker.update_alarmsdb_cache
'
)
return
Response
(
"
OK
"
)
@routes.route
(
"
update-services
"
,
methods
=
[
'
GET
'
])
def
update_service
():
config
=
current_app
.
config
[
'
INVENTORY_PROVIDER_CONFIG
'
]
...
...
This diff is collapsed.
Click to expand it.
inventory_provider/tasks/worker.py
+
33
−
0
View file @
8b13a7f0
...
...
@@ -6,8 +6,10 @@ import redis
from
lxml
import
etree
from
inventory_provider.tasks.app
import
app
from
inventory_provider
import
alarmsdb
from
inventory_provider
import
config
from
inventory_provider
import
constants
from
inventory_provider
import
db
from
inventory_provider
import
environment
from
inventory_provider
import
snmp
from
inventory_provider
import
juniper
...
...
@@ -38,6 +40,25 @@ class InventoryTask(Task):
"
saved %s, key %s
"
%
(
hostname
,
key
))
return
"
OK
"
@staticmethod
def
save_value
(
key
,
value
):
assert
isinstance
(
value
,
str
),
\
"
sanity failure: expected string data as value
"
r
=
redis
.
StrictRedis
(
host
=
InventoryTask
.
config
[
"
redis
"
][
"
hostname
"
],
port
=
InventoryTask
.
config
[
"
redis
"
][
"
port
"
])
r
.
set
(
name
=
key
,
value
=
value
)
InventoryTask
.
logger
.
debug
(
"
saved %s
"
%
key
)
return
"
OK
"
@staticmethod
def
save_value_json
(
key
,
data_obj
):
InventoryTask
.
save_value
(
key
,
json
.
dumps
(
data_obj
))
@staticmethod
def
save_key_json
(
hostname
,
key
,
data_obj
):
InventoryTask
.
save_key
(
...
...
@@ -102,3 +123,15 @@ def netconf_refresh_config(self, hostname):
juniper
.
load_config
(
hostname
,
InventoryTask
.
config
[
"
ssh
"
]))
logger
.
debug
(
'
FINISHED: netconf_refresh_config(%r)
'
%
hostname
)
@app.task
(
bind
=
InventoryTask
)
def
update_alarmsdb_cache
(
self
):
logger
=
logging
.
getLogger
(
constants
.
TASK_LOGGER_NAME
)
logger
.
debug
(
'
STARTING: update_alarmsdb_cache
'
)
with
db
.
connection
(
InventoryTask
.
config
[
"
alarms-db
"
])
as
cx
:
for
table_name
,
data
in
alarmsdb
.
load_cache
(
cx
):
InventoryTask
.
save_value_json
(
'
alarmsdb:%s
'
%
table_name
,
data
)
logger
.
debug
(
'
FINISHED: update_alarmsdb_cache
'
)
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