-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicinga2.py
More file actions
executable file
·63 lines (48 loc) · 2.37 KB
/
icinga2.py
File metadata and controls
executable file
·63 lines (48 loc) · 2.37 KB
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
#!/usr/bin/python
import argparse
import sys
import MySQLdb
import requests
import os
parser = argparse.ArgumentParser(description='Add server to Icinga2')
parser.add_argument('host',
help="Host Name")
parser.add_argument('address',
help="IP address or hostname")
parser.add_argument('display_name',
help="display_name")
parser.add_argument('vars_service',
choices=['cleanspeak', 'cron', 'admin', 'smartfox', 'PHP', 'sessions', 'Redis', 'playerDB', 'playercoreDB', 'tournamentDB', 'bannerDB', 'gameDB', 'coreDB', 'transactionDB'],
help="Service Name")
parser.add_argument('vars_role',
choices=['role1', 'role2', 'role3'],
help="Service Name")
parser.add_argument('vars_production',
choices=['YES', 'NO'],
help="Production Server")
parser.add_argument('vars_datacenter',
choices=['IAD', 'ATL', 'LAX'],
help="Datacenter Name")
parser.add_argument('vars_app',
choices=['Bingo-Blitz', 'Bingo-Rush', 'TRS'],
help="App Name")
parser.add_argument('vars_type',
choices=['applications', 'Couchbase', 'Redis', 'MySQL'],
help="Type Name")
parser.add_argument('vars_cpu',
choices=['cpu_load_0_10', 'cpu_load_0_15', 'cpu_load_0_20', 'cpu_load_0_60'],
help="CPU thresholds")
args = parser.parse_args()
#conn = MySQLdb.connect(host= "localhost",
# user="root",
# passwd="Alyan2757622",
# db="icinga")
#x = conn.cursor()
#try:
# x.execute("""INSERT INTO icinga_general (host, address, display_name, vars_service, vars_production, vars_datacenter, vars_app, vars_type) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)""",(args.host, args.address, args.display_name, args.vars_service, args.vars_production, args.vars_datacenter, args.vars_app, args.vars_type))
# conn.commit()
#except:
# conn.rollback()
#conn.close()
print(args.host)
os.system('curl -k -s -u icinga:icinga -H \'Accept: application/json\' -X PUT \'https://192.168.253.134:5665/v1/objects/hosts/%s\' -d \'{ "templates": [ "generic-host" ], "attrs": { "address": "%s", "check_command": "hostalive", "display_name" : "%s", "vars.service" : "%s", "vars.production" : "%s", "vars.datacenter" : "%s", "vars.app" : "%s", "vars.type" : "%s", "vars.role" : "%s", "vars.cpu" : "%s"} }\'' % (args.host, args.address, args.display_name, args.vars_service, args.vars_production, args.vars_datacenter, args.vars_app, args.vars_type, args.vars_role, args.vars_cpu))