-
Notifications
You must be signed in to change notification settings - Fork 23
/
make-nagios-fhservices-cfg
executable file
·98 lines (75 loc) · 4.24 KB
/
make-nagios-fhservices-cfg
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
import os
from jinja2 import Environment, FileSystemLoader, Template
fh_services = [
{'name': 'fh-messaging', 'checks': ['ping', 'health'], 'hostgroups': ['core']},
{'name': 'fh-messaging','service': 'fh-messaging-service', 'checks': ['ping', 'health'], 'hostgroups': ['mbaas']},
{'name': 'fh-metrics', 'checks': ['ping', 'health'], 'hostgroups': ['core']},
{'name': 'fh-metrics', 'service': 'fh-metrics-service', 'checks': ['ping', 'health'], 'hostgroups': ['mbaas']},
{'name': 'fh-ngui', 'checks': ['ping', 'health'], 'hostgroups': ['core']},
{'name': 'fh-supercore', 'checks': ['ping', 'health'], 'hostgroups': ['core']},
{'name': 'fh-aaa', 'checks': ['ping', 'health'], 'hostgroups': ['core']},
{'name': 'fh-appstore', 'checks': ['ping', 'health'], 'hostgroups': ['core']},
{'name': 'fh-scm', 'checks': ['ping', 'health'], 'hostgroups': ['core']},
{'name': 'fh-mbaas', 'service': 'fh-mbaas-service', 'checks': ['ping', 'health'], 'hostgroups': ['mbaas']},
{'name': 'fh-statsd', 'service': 'fh-statsd-service', 'checks': ['ping'], 'hostgroups': ['mbaas']},
{'name': 'millicore', 'checks': ['ping', 'health'], 'health_endpoint': '/box/api/health', 'ping_endpoint': '/box/srv/1.1/tst/version', 'hostgroups': ['core']},
{'name': 'ups', 'checks': ['ping', 'health'], 'health_endpoint': '/ag-push/rest/sys/info/health', 'ping_endpoint': '/ag-push/rest/sys/info/ping', 'hostgroups': ['core']}
]
rhmap_admin_email = os.getenv('RHMAP_ADMIN_EMAIL', 'root@localhost')
rhmap_router_dns = os.getenv('RHMAP_ROUTER_DNS', 'localhost')
rhmap_hostgroups = os.getenv('RHMAP_HOSTGROUPS', 'core')
try:
mongodb_count = int(os.getenv('MONGODB_ENDPOINT_COUNT', 3))
#if env var is an empty string or is not able to be converted into a number
except ValueError:
mongodb_count = 3
mongodb_services = ['mongodb-%s' % i for i in xrange(1, mongodb_count + 1)]
userdata_project_name = os.getenv('USERDATA_PROJECT_NAME')
userdata_mongodb_count = 0
if userdata_project_name:
try:
userdata_mongodb_count = int(os.getenv('USERDATA_MONGODB_ENDPOINT_COUNT', 3))
except ValueError:
userdata_mongodb_count = 3
userdata_mongodb_services = ['mongodb-%s' % i for i in xrange(1, userdata_mongodb_count + 1)]
try:
mysql_count = int(os.getenv('MYSQL_ENDPOINT_COUNT', 1))
#if env var is an empty string or is not able to be converted into a number
except ValueError:
mysql_count = 1
mysql_services = ['mysql'] + ['mysql-%s' % i for i in xrange(2, mysql_count + 1)]
jenkins_host = os.getenv('JENKINS_SERVICE_HOST')
jenkins_port = os.getenv('JENKINS_SERVICE_PORT')
jenkins_user = os.getenv('JENKINS_USER')
jenkins_pass = os.getenv('JENKINS_PASS')
check_android = False
check_mac = False
if rhmap_hostgroups == 'digger':
platforms = os.getenv('PLATFORMS')
if 'android' in platforms:
check_android = True
if 'ios' in platforms:
check_mac = True
template_file = '/opt/rhmap/fhservices.cfg.j2'
nagios_config_filename = '/etc/nagios/conf.d/fhservices.cfg'
template_basename = os.path.basename(template_file)
template_dirname = os.path.dirname(template_file)
j2env = Environment(loader=FileSystemLoader(template_dirname), trim_blocks=True)
j2template = j2env.get_template(template_basename)
j2renderedouput = j2template.render(fh_services=fh_services,
mongodb_services=mongodb_services,
mongodb_instances=mongodb_count,
mysql_services=mysql_services,
mysql_instances=mysql_count,
rhmap_hostgroups=rhmap_hostgroups,
rhmap_router_dns=rhmap_router_dns,
rhmap_admin_email=rhmap_admin_email,
jenkins_host=jenkins_host,
jenkins_port=jenkins_port,
jenkins_user=jenkins_user,
jenkins_pass=jenkins_pass,
check_android=check_android,
check_mac=check_mac)
with open(nagios_config_filename, 'wb') as nagios_config_file:
nagios_config_file.write(j2renderedouput)