-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleConfigMonitoring-python
More file actions
110 lines (100 loc) · 5.54 KB
/
SimpleConfigMonitoring-python
File metadata and controls
110 lines (100 loc) · 5.54 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
rm /tmp/version 2> /dev/null
size=`du -hs /home/MyApp/* | sort -rh | head -1 | awk '{print $1}';`
homesize=`df -h | grep home | awk '{print $5 }';`
mem=`free | grep Mem | awk '{print $3/$2 * 100.0}' | awk '{printf "%.0f",$1}'`
>/opt/app-ui/ui/index1.htm
now=$(date +"%Y-%m-%d %H-%M")
echo "<html><body><h1><center>App Monitoring v1.0 </center></h1> <table cellpadding=3 cellspacing=0 border=1 bgcolor=#FFB0B0> <th>No</th><th>CFG Name</th> <th>Uptime</> <th>IP-R1</th> <th>IP-R2</th> <th>Port R1</th><th>state</th> <th>Port R2</th><th>state</th> <th>Type R1</th> <th>Type R2</th> <th>Acqinst</th> <th>Mode</th> <th>Pid</th> <th>ErrorMessage</th> <th>log tail</th> <th>Dlog</th> <th>logpath</th> <th>01 valid</th> <th>02 valid</th> <th>Version</th> <th>PC</th> <th>MT</th> <th>PCC</th> <th>ISO</th>" >> /opt/app-ui/ui/index1.htm
cnt=0
counter=1
ps -e -o command | egrep ".*\A.*cfg" > /tmp/driver-process.log
while read recline
do
if [ `echo "$recline" | grep "grep" | wc -l` -gt 0 ]; then
continue
fi
drvexe=`echo "$recline" | awk '{print $1};'`
drvvers=`$drvexe -version | tr -d '[a-z][A-Z] '`
echo $drvvers >> /tmp/version
drvconf=`echo "$recline" | awk '{print $3};'`
drvconffile=`echo "$recline" | awk '{print $3};' | awk -F'/' '{print $NF};'`
pid=`pgrep -f $drvconffile`
uptime=`ps -p $pid -o etime | tr -d '[a-z][A-Z]' |sed '/^\s*$/d'`
confr1ip=`grep "^R1_IP" "$drvconf" | head -1 | awk '{print $2};'`
confr1port=`grep "^LISTEN_PORT_R1" "$drvconf" | head -1 | awk '{print $2};'`
stateport1=`netstat -ant | grep :$confr1port | awk '{print $6}' | sort | sort -n |awk '!NF || !seen[$0]++'`
confr1type=`grep "^CONNECTION_TYPE_R1" "$drvconf" | head -1 | awk '{print $2};'`
confr2ip=`grep "^S2_IP" "$drvconf" | head -1 | awk '{print $2};'`
confr2port=`grep "^CONNECT_PORT_R2" "$drvconf" | head -1 | awk '{print $2};'`
stateport2=`netstat -ant | grep :$confr2port | awk '{print $6}' | sort | sort -n |awk '!NF || !seen[$0]++' `
confr2type=`grep "^CONNECTION_TYPE_R2" "$drvconf" | head -1 | awk '{print $2};'`
conmode=`grep "^CONNECTION_MODE" "$drvconf" | head -1 | awk '{print $2};'`
customer=`grep "^CUSTOMER" "$driverconf" | head -1 | awk '{print $2};'`
logspath=`grep "^LOGPATH" "$driverconf" | head -1 | awk '{print $2};'`
logfile=`ls -d -rt $logspath/* | tail -2 | grep -v debug`
debuglog=`ls $logspath/debug.* | tail -1`
log=`tail -n5 $logfile | awk '!/ReConnect|TCPSPortNoDC/'`
cfr1=`grep "^CFR1" "$driverconf" | awk '{print $2};'`
cfr2=`grep "^CFR2" "$driverconf" | awk '{print $2};'`
# preiso=`grep "^CODE3" "$driverconf" | head -1 | awk '{print $2};'`
# pcc=`grep "^CODE1C" "$driverconf" | head -1 | awk '{print $2};'`
# mt=`grep "^CODE2" "$driverconf" | head -1 | awk '{print $2 $3 $4 $5 $6 $7 $8 $7 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20};'`
# pc=`grep "^CODE1" "$driverconf" | head -1 | awk '{print $2 $3 $4 $5 $6 $7 $8 $7 $9 $10 $11 $12 $13 $14 $15 $16 $17 $18 $19 $20};'`
reason=`grep ErrorMessage $debuglog | head -1 | awk '{print $3};'`
dlog=`grep M $debuglog | tail -2`
if [ -f "$cfr1/01" ]; then
startr1pub=`openssl x509 -in "$cfr1/01" -text | egrep "Not After" | sed -r 's/:/\t/g' | awk '{print $3" "$4" "$8}' | sed 'N;s/\n/ /'`
else
startr1pub=""
fi
if [ -f "$cfr2/02" ]; then
startr2pub=`openssl x509 -in "$cfr2/02" -text | egrep "Not After" | sed -r 's/:/\t/g' | awk '{print $3" "$4" "$8}' | sed 'N;s/\n/ /'`
else
startr2pub=""
fi
if [ `echo "$counter%2" | bc` -eq 0 ]; then
coloring="#fff"
else
coloring="#89ff8a"
fi
echo "<tr style='background-color:$coloring'> <td>$((cnt+=1))</td>
<td>$driverconffile</td>
<td>$uptime</td>
<td>$confr1ip</td>
<td>$confr2ip</td>
<td>$confr1port</td>
<td><font size="1">$stateport1</font></td>
<td>$confr2port</td>
<td><font size="1">$stateport2</font></td>
<td><font size="1">$confr1type</font></td>
<td><font size="1">$confr2type</font></td>
<td><font size="1">$customer</font></td>
<td><font size="1">$conmode</font></td>
<td><font size="1">$pid</font></td>
<td><font size="1">$reason</font></td>
<td><font size="1">$log</font></td>
<td><font size="1">$dlog</font></td>
<td><font size="1">$logspath</font></td>
<td><font size="1">$startr1pub</font></td>
<td><font size="1">$startr2pub</font></td>
<td>$drvvers</td>
<td><font size="1">$code1</font></td>
<td><font size="1">$code2</font></td>
<td><font size="1">$code1c</font></td>
<td><font size="1">$code3</font></td>
</tr>
" >> /opt/app-ui/ui/index1.htm
counter=`echo "$counter+1" | bc`
#TShoot
#echo "$driverconffile $uptime $confr1ip $confr2ip $confr1port $stateport1 $confr2port $stateport2 $confr1type $confr2type $customer $conmode $log $logspath $startr1pub $startr2pub $drvvers"
done < /tmp/driver-process.log
otherver=`echo "$(</tmp/version)" | tr '[:space:]' '[\n*]' | grep -v "^\s*$" | sort | uniq -c | sort -bnr | paste -sd, -`
echo "<h3><center>Status Total: $cnt, Group by version: $otherver, Log Size:$size Disk Usage:$homesize Mem Usage: $mem% </center> </h3> " >> /opt/app-ui/ui/index1.htm
echo "<html><body><h3><center> Time: "$now" (data refresh every 1 minute) </center></h3></body></html>" >> /opt/app-ui/ui/index1.htm
echo "<html><body><h3><center> IP App Internal "192.168.0.1" External "192.168.2.1" Gateway "192.168.1.1" </center></h3></body></html>" >> /opt/app-ui/ui/index1.htm
echo "</table></body></html>" >> /opt/app-ui/ui/index1.htm
mv /opt/app-ui/ui/index1.htm /opt/app-ui/ui/index.htm
pkill python
cd /opt/app-ui/ui
python -m SimpleHTTPServer 8000 &