-
Notifications
You must be signed in to change notification settings - Fork 3
/
tower_diagnose_ping
executable file
·39 lines (32 loc) · 1.19 KB
/
tower_diagnose_ping
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Import required python modules
import requests,json,getpass
import os,sys
import ConfigParser
#Disabling InsecureRequestWarnings in python requests module
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def tower_ping(url, user, passwd):
"""This function returns the
ping api endpoint and store the output
in a text file"""
try:
req = requests.get(url + '/api/v2/ping', auth=(user, passwd), verify=False)
results = str(json.dumps(req.json(), sort_keys=True, indent=4))
write(results)
except requests.exceptions.ConnectionError as error:
print('Unable to GET api ping endpoint due to error : {0} '. format(error))
def write(results):
f = open('ping_status.txt','w')
f.write(results)
f.close()
if __name__ == '__main__':
#Read Config
config = ConfigParser.SafeConfigParser()
config.read('config.ini')
url = config.get('tower', 'url')
user = config.get('tower', 'username')
passwd = config.get('tower', 'password')
# calling tower_ping function
tower_ping(url, user, passwd)