-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_handler.yml
58 lines (53 loc) · 1.78 KB
/
db_handler.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
- name: Get and Write NAPALM data to DB
hosts: network_devices
gather_facts: no
vars:
used_influxdb_ip_address: 10.10.10.6
used_influxdb_ansible_database_name: "monitoring_ansible"
tasks:
- name: Get env_details and device facts
napalm_get_facts:
provider: "{{ napalm_provider }}"
filter: environment,facts
register: result
- name: Get current UTC time
command: "date '+%Y-%m-%d %H:%M:%S'"
delegate_to: localhost
register: date_utc
environment:
TZ: UTC
run_once: yes
- name: Access HW details (except Olive)
set_fact:
cpu_usage: "{{ (result['ansible_facts']['napalm_environment']['cpu']['0']['%usage']) }}"
when: image != "olive"
- name: Access facts (uptime)
set_fact:
uptime: "{{ result['ansible_facts']['napalm_facts']['uptime'] }}"
- name: Write HW details into DB
community.general.influxdb_write:
hostname: "{{ used_influxdb_ip_address }}"
database_name: "{{ used_influxdb_ansible_database_name }}"
data_points:
- measurement: hw_details
tags:
host: "{{ inventory_hostname }}"
time: "{{ date_utc.stdout }}"
fields:
cpu_usage: "{{ cpu_usage }}"
throttle: 1
when: cpu_usage is defined
- name: Write device facts into DB
community.general.influxdb_write:
hostname: "{{ used_influxdb_ip_address }}"
database_name: "{{ used_influxdb_ansible_database_name }}"
data_points:
- measurement: device_facts
tags:
host: "{{ inventory_hostname }}"
time: "{{ date_utc.stdout }}"
fields:
uptime: "{{ uptime }}"
throttle: 1
when: uptime is defined