Skip to content

Commit bed9cb2

Browse files
committed
add zabbix monitor status check script
1 parent c99f5fa commit bed9cb2

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

ansible/roles/os_zabbix/vars/template_openshift_master.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ g_template_openshift_master:
845845
applications:
846846
- Openshift Master
847847

848+
- key: openshift.master.zabbix.inventory.status
849+
value_type: int
850+
description: "zabbix monitor status check see if zabbix monitor all the node"
851+
applications:
852+
- Openshift Master
853+
848854
zdiscoveryrules:
849855
- name: disc.pv
850856
key: disc.pv
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python
2+
''' collect info of zabbix and compare with info on master '''
3+
4+
# TODO: change to use arguments for podname, and run once per podname
5+
6+
#pylint: disable=import-error
7+
#pylint: disable=invalid-name
8+
#pylint: disable=broad-except
9+
10+
import argparse
11+
import logging
12+
import json
13+
import urllib2
14+
import sys
15+
from urllib2 import Request, urlopen, URLError, HTTPError
16+
from openshift_tools.monitoring.ocutil import OCUtil
17+
from openshift_tools.monitoring.metric_sender import MetricSender
18+
sys.path.insert(0, '/container_setup')
19+
from zabbix_data_sync import *
20+
21+
logging.basicConfig(
22+
format='%(asctime)s - %(relativeCreated)6d - %(levelname)-8s - %(message)s',
23+
)
24+
logging.getLogger().setLevel(logging.WARN)
25+
26+
class ZabbixInfo(object):
27+
'''
28+
this will check the zabbix data and compare it with the real world
29+
'''
30+
def __init__(self, args=None, ):
31+
'''initial for the InfraNodePodStatus'''
32+
self.args = args
33+
self.kubeconfig = '/tmp/admin.kubeconfig'
34+
self.oc = OCUtil(namespace=self.args.namespace, config_file=self.kubeconfig)
35+
36+
def check_all_hosts(self, zabbix_data_sync_inventory_hosts, clusterid):
37+
''' check the situation '''
38+
result = 1
39+
zabbix_data_sync_inventory_hosts_names = []
40+
for host in zabbix_data_sync_inventory_hosts:
41+
zabbix_data_sync_inventory_hosts_names.append(host['name'])
42+
43+
desire_number_cluster = cluster_desired_compute_size + cluster_desired_infra_size + cluster_desired_master_size
44+
logging.getLogger().info("the requested number of instance is :" + str(desire_number_cluster))
45+
hosts = self.oc.get_nodes()
46+
#print hosts
47+
for host in hosts['items']:
48+
hostnameincluster = ""
49+
if host['metadata']['labels']['type'] == 'master':
50+
hostnameincluster = host['metadata']['labels']['hostname']
51+
elif host['metadata']['labels']['type'] == 'infra':
52+
hostnameincluster = clusterid + "-infra-" + host['metadata']['labels']['kubernetes.io/hostname']
53+
else:
54+
hostnameincluster = clusterid + "-compute-" + host['metadata']['labels']['kubernetes.io/hostname']
55+
56+
if hostnameincluster in zabbix_data_sync_inventory_hosts_names:
57+
logging.getLogger().info("found host in zabbix :" + str(hostnameincluster))
58+
else:
59+
result = 0
60+
logging.getLogger().info("host not in zabbix:" + str(hostnameincluster))
61+
62+
if result == 1:
63+
if len(hosts['items']) == desire_number_cluster:
64+
logging.getLogger().info("currrently cluster have :" + str(len(hosts['items'])))
65+
logging.getLogger().info("all the node under monitoring and the number is the same as requested:" + str(desire_number_cluster))
66+
else:
67+
result = 2
68+
logging.getLogger().info("cluster node number is different with requested")
69+
70+
return result
71+
72+
def send_metrics(self, status):
73+
"""send_metrics"""
74+
ms = MetricSender(verbose=self.args.verbose)
75+
ms.add_metric({'openshift.master.zabbix.inventory.status': status})
76+
ms.send_metrics()
77+
78+
def parse_args():
79+
""" parse the args from the cli """
80+
logging.getLogger().debug("parse_args()")
81+
parser = argparse.ArgumentParser(description='AWS instance health')
82+
parser.add_argument('-v', '--verbose', action='count', default=0,
83+
help='verbosity level, specify multiple')
84+
parser.add_argument('--clusterid', default="default",
85+
help='clusterid')
86+
parser.add_argument('--namespace', default="default",
87+
help='Project namespace')
88+
args = parser.parse_args()
89+
if args.verbose > 0:
90+
logging.getLogger().setLevel(logging.DEBUG)
91+
return args
92+
93+
if __name__ == '__main__':
94+
status = 1
95+
ZABBIX = ZabbixInfo(args=parse_args(), )
96+
status = ZABBIX.check_all_hosts(zabbix_data_sync_inventory_hosts, ZABBIX.args.clusterid)
97+
ZABBIX.send_metrics(status)

scripts/openshift-tools-scripts.spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ cp -p monitoring/cron-send-aws-eip-check.py %{buildroot}/usr/bin/cron-send-aws-e
101101
cp -p monitoring/cron-send-pod-check.py %{buildroot}/usr/bin/cron-send-pod-check
102102
cp -p monitoring/cron-send-ssl-check.py %{buildroot}/usr/bin/cron-send-ssl-check
103103
cp -p monitoring/cron-send-node-pods-status.py %{buildroot}/usr/bin/cron-send-node-pods-status
104+
cp -p monitoring/cron-send-zabbix-inventory-check.py %{buildroot}/usr/bin/cron-send-zabbix-inventory-check
104105

105106
mkdir -p %{buildroot}/etc/openshift_tools
106107
cp -p monitoring/metric_sender.yaml.example %{buildroot}/etc/openshift_tools/metric_sender.yaml
@@ -415,6 +416,8 @@ OpenShift Tools Openshift Product Scripts
415416
/usr/bin/cron-send-aws-eip-check
416417
/usr/bin/cron-send-pod-check
417418
/usr/bin/cron-send-ssl-check
419+
/usr/bin/cron-send-zabbix-inventory-check
420+
418421

419422
# ----------------------------------------------------------------------------------
420423
# openshift-tools-scripts-monitoring-zabbix-heal subpackage

0 commit comments

Comments
 (0)