Skip to content

Commit 1c30ef1

Browse files
author
Tomasz Cholewa
committed
Add hypervisor discovery and new template for active monitoring of nodes
1 parent 3ec9db9 commit 1c30ef1

File tree

5 files changed

+2612
-52
lines changed

5 files changed

+2612
-52
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# Monitoring OpenStack with Zabbix
22

3-
This repository contains zabbix resources for monitoring OpenStack environment.
3+
This repository contains Zabbix resources for monitoring OpenStack environment.
44

55
# Features
66
The following features are currently available:
7-
* Automatic endpoints discovery via keystone API
8-
* Endpoints monitoring with predefined triggers
9-
* Configuration using macros
7+
* Automatically discover (using API), add service endpoints and monitor their availability and performance
8+
* Automatically discover (using API), add hypervisor hosts and monitor availability, performance and other metrics
9+
* Active monitoring of OpenStack nodes - connections are initiated by agents installed on nodes
10+
* Flexible configuration based on variables (Zabbix macros)
1011

1112
# Installation
12-
* Install **python-keystoneclient** on you Zabbix server
13+
* Install **python-keystoneclient** and **python-novaclient** on you Zabbix server
14+
* Install Zabbix agents on your OpenStack nodes and define **ServerActive** with IP address of the Zabbix server
1315
* Copy scripts from **server/externalscripts/** to your Zabbix server to **ExternalScripts** location
14-
* Import **templates/Template_OpenStack_Services.xml** template into your Zabbix server
15-
* Add OpenStack controller host (the one with Keystone component) to Zabbix and link **Template OpenStack Services** template to it
16+
* Import templates from **templates/** into your Zabbix server
17+
* Add OpenStack controller host (the one with Keystone component) to Zabbix and link **Template OpenStack** template to it
18+
* Wait for Zabbix to add discovered hypervisor hosts and endpoints items (look for them in the controller host)
1619

1720
# Configuration
1821
Configure the following macros on the **controller host level** in Zabbix so that server could connect to keystone:
@@ -21,6 +24,8 @@ Configure the following macros on the **controller host level** in Zabbix so tha
2124
* **{$OS_USER}** - OpenStack user name (*admin* by default)
2225
* **{$OS_PASSWORD}** - OpenStack user password (*admin* by default)
2326

27+
28+
2429
# License
2530
This project is licensed under Apache License 2.0
2631

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python
2+
3+
4+
from sys import exit
5+
from sys import argv
6+
from sys import stderr
7+
import json
8+
from datetime import datetime
9+
import re
10+
11+
12+
try:
13+
from keystoneclient.v2_0 import client as keystone_client
14+
from keystoneclient.auth.identity import v2
15+
from keystoneclient import session
16+
from novaclient import client as nova_client
17+
except ImportError:
18+
print 'ZBX_NOTSUPPORTED\x00 Failed to import openstack python modules'
19+
exit(1)
20+
21+
def get_host_port(url):
22+
m = re.match('https?://(\d+\.\d+\.\d+\.\d+):(\d+)',url)
23+
if m:
24+
return (m.group(1),m.group(2))
25+
26+
def print_json(data):
27+
print json.dumps({'data':data},sort_keys=True,indent=7,separators=(',',':'))
28+
29+
def discover_endpoints(auth_url, tenant_name, username, password):
30+
conn = keystone_client.Client(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url)
31+
32+
services = []
33+
for e in conn.endpoints.list():
34+
host = get_host_port(e.publicurl)
35+
if e.enabled:
36+
service = conn.services.get(e.service_id)
37+
services.append({'{#OS_SERVICENAME}':service.name, '{#OS_SERVICEURL}':e.publicurl, '{#OS_SERVICEHOST}':host[0], '{#OS_SERVICEPORT}':host[1] })
38+
39+
print_json(services)
40+
41+
def discover_hypervisors(auth_url, tenant_name, username, password):
42+
auth = v2.Password(username=username, password=password, tenant_name=tenant_name, auth_url=auth_url)
43+
sess = session.Session(auth=auth)
44+
45+
conn = nova_client.Client(2, session=sess)
46+
47+
hypervisors = []
48+
for h in conn.hypervisors.list(detailed=True):
49+
if h.status == 'enabled':
50+
hypervisors.append({'{#OS_HYPERVISOR_HOSTNAME}':h.hypervisor_hostname, '{#OS_HYPERVISOR_IP}':h.host_ip, '{#OS_HYPERVISOR_TYPE}':h.hypervisor_type })
51+
52+
print_json(hypervisors)
53+
54+
if __name__ == '__main__':
55+
56+
if (len(argv) != 6):
57+
print """Usage: %s TYPE AUTH_URL TENANT USERNAME PASSWORD
58+
where
59+
60+
TYPE - one of the following: endpoints hypervisors
61+
AUTH_URL - URL to keystone
62+
TENANT - tenant name
63+
USERNAME - user name
64+
PASSWORD - password for user
65+
""" % argv[0]
66+
exit(2)
67+
else:
68+
(TYPE,AUTH_URL,TENANT,USERNAME,PASSWORD) = argv[1:]
69+
70+
if TYPE == 'endpoints':
71+
discover_endpoints(AUTH_URL,TENANT,USERNAME,PASSWORD)
72+
elif TYPE == 'hypervisors':
73+
discover_hypervisors(AUTH_URL,TENANT,USERNAME,PASSWORD)
74+
else:
75+
print 'ZBX_NOTSUPPORTED\x00 Unknown type: %s' % TYPE
76+
exit(1)
77+
78+
79+

server/externalscripts/openstack-endpoints-discovery

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<zabbix_export>
33
<version>2.0</version>
4-
<date>2015-06-03T11:22:07Z</date>
4+
<date>2015-06-25T10:43:58Z</date>
55
<groups>
6+
<group>
7+
<name>Discovered hosts</name>
8+
</group>
69
<group>
710
<name>Templates</name>
811
</group>
912
</groups>
1013
<templates>
1114
<template>
12-
<template>Template OpenStack Services</template>
13-
<name>Template OpenStack Services</name>
15+
<template>Template OpenStack</template>
16+
<name>Template OpenStack</name>
1417
<groups>
1518
<group>
1619
<name>Templates</name>
1720
</group>
1821
</groups>
1922
<applications>
23+
<application>
24+
<name>OpenStack Compute</name>
25+
</application>
2026
<application>
2127
<name>Openstack Endpoints</name>
2228
</application>
2329
</applications>
2430
<items/>
2531
<discovery_rules>
2632
<discovery_rule>
27-
<name>OpenStack Endpoints discovery</name>
33+
<name>OpenStack Compute Hypervisor</name>
2834
<type>10</type>
2935
<snmp_community/>
3036
<snmp_oid/>
31-
<key>openstack-endpoints-discovery[{$OS_AUTHURL},{$OS_TENANT},{$OS_USER},{$OS_PASSWORD}]</key>
37+
<key>openstack-discovery[hypervisors,{$OS_AUTHURL},{$OS_TENANT},{$OS_USER},{$OS_PASSWORD}]</key>
3238
<delay>3600</delay>
3339
<status>0</status>
3440
<allowed_hosts/>
@@ -51,14 +57,70 @@
5157
<filter>:</filter>
5258
<lifetime>7</lifetime>
5359
<description/>
60+
<item_prototypes/>
61+
<trigger_prototypes/>
62+
<graph_prototypes/>
63+
<host_prototypes>
64+
<host_prototype>
65+
<host>{#OS_HYPERVISOR_HOSTNAME}</host>
66+
<name>{#OS_HYPERVISOR_HOSTNAME}</name>
67+
<status>0</status>
68+
<group_links>
69+
<group_link>
70+
<group>
71+
<name>Discovered hosts</name>
72+
</group>
73+
</group_link>
74+
</group_links>
75+
<group_prototypes>
76+
<group_prototype>
77+
<name>OpenStack {#OS_HYPERVISOR_TYPE} Hypervisors</name>
78+
</group_prototype>
79+
</group_prototypes>
80+
<templates>
81+
<template>
82+
<name>Template OpenStack Node</name>
83+
</template>
84+
</templates>
85+
</host_prototype>
86+
</host_prototypes>
87+
</discovery_rule>
88+
<discovery_rule>
89+
<name>OpenStack Endpoints</name>
90+
<type>10</type>
91+
<snmp_community/>
92+
<snmp_oid/>
93+
<key>openstack-discovery[endpoints,{$OS_AUTHURL},{$OS_TENANT},{$OS_USER},{$OS_PASSWORD}]</key>
94+
<delay>3600</delay>
95+
<status>0</status>
96+
<allowed_hosts/>
97+
<snmpv3_contextname/>
98+
<snmpv3_securityname/>
99+
<snmpv3_securitylevel>0</snmpv3_securitylevel>
100+
<snmpv3_authprotocol>0</snmpv3_authprotocol>
101+
<snmpv3_authpassphrase/>
102+
<snmpv3_privprotocol>0</snmpv3_privprotocol>
103+
<snmpv3_privpassphrase/>
104+
<delay_flex/>
105+
<params/>
106+
<ipmi_sensor/>
107+
<authtype>0</authtype>
108+
<username/>
109+
<password/>
110+
<publickey/>
111+
<privatekey/>
112+
<port/>
113+
<filter>:</filter>
114+
<lifetime>30</lifetime>
115+
<description/>
54116
<item_prototypes>
55117
<item_prototype>
56-
<name>Endpoint status of {#SERVICENAME} on host {#SERVICEHOST}</name>
57-
<type>0</type>
118+
<name>Response time of endpoint {#OS_SERVICENAME} on host {#OS_SERVICEHOST}</name>
119+
<type>3</type>
58120
<snmp_community/>
59121
<multiplier>0</multiplier>
60122
<snmp_oid/>
61-
<key>net.tcp.service.perf[http,{#SERVICEHOST},{#SERVICEPORT}]</key>
123+
<key>net.tcp.service.perf[http,{#OS_SERVICEHOST},{#OS_SERVICEPORT}]</key>
62124
<delay>60</delay>
63125
<history>90</history>
64126
<trends>365</trends>
@@ -98,12 +160,12 @@
98160
</item_prototypes>
99161
<trigger_prototypes>
100162
<trigger_prototype>
101-
<expression>{Template OpenStack Services:net.tcp.service.perf[http,{#SERVICEHOST},{#SERVICEPORT}].last(0)}=0</expression>
102-
<name>Endpoint of service {#SERVICENAME} on host {#SERVICEHOST} is unavailable</name>
163+
<expression>{Template OpenStack:net.tcp.service.perf[http,{#OS_SERVICEHOST},{#OS_SERVICEPORT}].sum(#2)}=0</expression>
164+
<name>Endpoint of service {#OS_SERVICENAME} on host {#OS_SERVICEHOST} is unavailable</name>
103165
<url/>
104166
<status>0</status>
105167
<priority>3</priority>
106-
<description/>
168+
<description>Trigger an event if we couldn't get proper connections over last 2 checks.</description>
107169
<type>0</type>
108170
</trigger_prototype>
109171
</trigger_prototypes>

0 commit comments

Comments
 (0)