-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_service_check.py
More file actions
70 lines (53 loc) · 2.18 KB
/
Copy pathssh_service_check.py
File metadata and controls
70 lines (53 loc) · 2.18 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
64
65
66
67
68
69
70
import os
from dotenv import load_dotenv
import time
import json
import argparse
import logging
import sys
import datetime, time
import warnings
from ssh_client import utils, work
warnings.filterwarnings("ignore")
''' pip install python-dotenv'''
load_dotenv() # will search for .env file in local folder and load variables
# Configure basic logging to console with INFO level and a custom format
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
stream=sys.stdout)
if __name__ == '__main__':
''' Service checking using the command remotely'''
parser = argparse.ArgumentParser(description="Script that might allow us to run the commands")
parser.add_argument('--env', dest='env', default="env", help='env name')
parser.add_argument('--service', dest='service', default="kibana", help='service name')
parser.add_argument('--cmd', dest='cmd', default="cmd", help='start/stop')
args = parser.parse_args()
if args.env:
env = args.env
if args.service:
service = args.service
if args.cmd:
cmd = args.cmd
''' load ssh_config.json'''
ssh_config = utils.load_json_config("./ssh_config.json", env)
logging.info(json.dumps(ssh_config, indent=2))
''' multiple services'''
service_list = service.split(",")
response_list_dict = []
try:
for service in service_list:
logging.info(f"service : {service}\n")
''' call to perform the ssh commands'''
response = work(ssh_config, service, cmd)
# logging.info(f"response : {json.dumps(response, indent=2)}\n")
response_list_dict.append(response)
''' Move to the next services to start it if status is 200'''
if response.get("status") == 200:
continue
else:
break
logging.info(f"response_list_dict : {json.dumps(response_list_dict, indent=2)}\n")
except Exception as e:
logging.error(f"An error occurred: {e}")
finally:
logging.info(f"** [{env}] Job is being performed..")