-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcentreon.py
47 lines (30 loc) · 1.07 KB
/
centreon.py
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
#!/usr/bin/env python
# need to: pipenv install requests
import requests
import configparser
import argparse
# -------------------------------------------------------------------------
# parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('--list', action='store_true', help='List active servers')
parser.add_argument('--host', help='List details about the specific host')
args = parser.parse_args()
# -------------------------------------------------------------------------
# parse config
CONFIG_FILE = '/etc/ansible/centreon.ini'
config = configparser.SafeConfigParser()
config.read(CONFIG_FILE)
url = 'localhost/ansible/inventory/'
if config.has_option('centreon', 'url'):
url = config.get('centreon', 'url')
# -------------------------------------------------------------------------
# call Centreon inventory API
if args.list:
url += "list"
elif args.host:
url += "host/" + args.host
resp = requests.get(url=url)
# -------------------------------------------------------------------------
# answer
# resp.encoding = 'ASCII'
print(resp.text)