Browse Source

add diagnose

develop
Emmanuel Garette 4 months ago
parent
commit
77eabcfaef
2 changed files with 70 additions and 0 deletions
  1. 66
    0
      diagnose/10-keepalived
  2. 4
    0
      dicos/19_keepalived.xml

+ 66
- 0
diagnose/10-keepalived View File

@@ -0,0 +1,66 @@
1
+#!/usr/bin/env python3
2
+
3
+from os import remove, system
4
+from os.path import isfile
5
+from sys import exit
6
+from time import sleep
7
+from subprocess import run, PIPE
8
+from creole.client import CreoleClient
9
+
10
+data_file = '/tmp/keepalived.data'
11
+pid_file = '/var/run/keepalived.pid'
12
+separator_instance = ' VRRP Instance = '
13
+state_text = 'State = '
14
+
15
+
16
+if isfile(data_file):
17
+    remove(data_file)
18
+
19
+client = CreoleClient()
20
+if client.get_creole('keepalivedEnable') == 'non':
21
+    exit(0)
22
+
23
+keepVRRPInstance = client.get_creole('keepVRRPInstance')
24
+kVRRPState = client.get_creole('kVRRPState')
25
+if isfile(pid_file):
26
+    with open(pid_file) as fh:
27
+        pid = int(fh.read().strip())
28
+    signal = int(run(['keepalived', '--signum=DATA'], stdout=PIPE).stdout.decode())
29
+    run(['kill', '-s', str(signal), str(pid)])
30
+    idx = 0
31
+    while not isfile(data_file):
32
+        idx += 1
33
+        sleep(.1)
34
+        if idx == 60:
35
+            print('{} not found'.format(data_file))
36
+            exit(1)
37
+    cmd = ['. /usr/lib/eole/diagnose.sh']
38
+    cmd.append('EchoGras "*** Keepalived"')
39
+    with open(data_file) as fh:
40
+        instance = None
41
+        for line in fh.readlines():
42
+            line = line.rstrip()
43
+            if line.startswith(separator_instance):
44
+                instance = line[len(separator_instance):]
45
+            else:
46
+                line = line.strip()
47
+                if line.startswith(state_text):
48
+                    if instance is None:
49
+                        print('no instance!')
50
+                        exit(1)
51
+                    idx = keepVRRPInstance.index(instance)
52
+                    cmd.append('printf ".  %$((len_pf+1))s => " "{}"'.format(instance))
53
+                    state = line[len(state_text):]
54
+                    if kVRRPState[idx] == state:
55
+                        cmd.append('EchoVert "{}"'.format(state))
56
+                    else:
57
+                        cmd.append('EchoRouge "{}"'.format(state))
58
+    cmd.append('echo')
59
+    cmd_string = "\n".join(cmd)
60
+    run(cmd_string, shell=True)
61
+
62
+else:
63
+    print('is keepalived running?')
64
+    exit(1)
65
+if isfile(data_file):
66
+    remove(data_file)

+ 4
- 0
dicos/19_keepalived.xml View File

@@ -75,6 +75,10 @@
75 75
             <target type='filelist'>keepalived</target>
76 76
             <target type='servicelist'>slKeepalive</target>
77 77
         </condition>
78
+	<check name='valid_entier' target='keepVRRPRouterID'>
79
+            <param name="mini">1</param>
80
+            <param name="maxi">255</param>
81
+        </check>
78 82
         <fill name='calc_val' target='keepSMTPServer'>
79 83
             <param type='eole' hidden='False' name='valeur'>exim_relay_smtp</param>
80 84
         </fill>

Loading…
Cancel
Save