1 |
|
# Copyright 2018 Whitestack, LLC |
2 |
|
# ************************************************************* |
3 |
|
|
4 |
|
# This file is part of OSM Monitoring module |
5 |
|
# All Rights Reserved to Whitestack, LLC |
6 |
|
|
7 |
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
8 |
|
# not use this file except in compliance with the License. You may obtain |
9 |
|
# a copy of the License at |
10 |
|
|
11 |
|
# http://www.apache.org/licenses/LICENSE-2.0 |
12 |
|
|
13 |
|
# Unless required by applicable law or agreed to in writing, software |
14 |
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
15 |
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
16 |
|
# License for the specific language governing permissions and limitations |
17 |
|
# under the License. |
18 |
|
|
19 |
|
# For those usages not covered by the Apache License, Version 2.0 please |
20 |
|
# contact: bdiaz@whitestack.com or glavado@whitestack.com |
21 |
|
## |
22 |
0 |
import argparse |
23 |
0 |
import logging |
24 |
0 |
import subprocess |
25 |
0 |
import sys |
26 |
0 |
import os |
27 |
|
|
28 |
0 |
log = logging.getLogger(__name__) |
29 |
|
|
30 |
|
|
31 |
0 |
def main(): |
32 |
0 |
parser = argparse.ArgumentParser(prog='osm-policy-healthcheck') |
33 |
0 |
parser.add_argument('--config-file', nargs='?', help='POL configuration file') |
34 |
|
# args = parser.parse_args() |
35 |
|
# cfg = Config(args.config_file) |
36 |
|
|
37 |
0 |
if not _processes_running(): |
38 |
0 |
sys.exit(1) |
39 |
0 |
sys.exit(0) |
40 |
|
|
41 |
|
|
42 |
0 |
def _processes_running(): |
43 |
0 |
def _contains_process(processes, process_name): |
44 |
0 |
for row in processes: |
45 |
0 |
if process_name in row: |
46 |
0 |
return True |
47 |
0 |
return False |
48 |
|
|
49 |
0 |
processes_to_check = ['osm-policy-agent'] |
50 |
0 |
ps = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).communicate()[0] |
51 |
0 |
processes_running = ps.decode().split('\n') |
52 |
0 |
for p in processes_to_check: |
53 |
0 |
if not _contains_process(processes_running, p): |
54 |
0 |
log.error("Process %s not running!" % p) |
55 |
0 |
return False |
56 |
|
|
57 |
|
# Check if process is running properly (listening to kafka bus) |
58 |
0 |
if os.path.exists('/tmp/osm_pol_agent_health_flag'): |
59 |
0 |
return True |
60 |
|
else: |
61 |
0 |
return False |
62 |
|
|
63 |
|
|
64 |
0 |
if __name__ == '__main__': |
65 |
0 |
main() |