-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpodcount.sh
73 lines (66 loc) · 1.87 KB
/
podcount.sh
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
#!/bin/bash
kubectl get ns | grep -i supplychain | awk '{print $1}' | tail -n +2 > namespaces.txt
for word in $(cat namespaces.txt)
do
if kubectl get pods -n $word > /dev/null 2>&1
then
for i in $(echo `kubectl get pods -n $word | awk '$5 != "0" {print $0}' | awk 'FNR>=2 {print $1"," $4"," $5}'`); do echo $word",$i" >> podDetail.csv; done;
fi
done
tableStart="<html>
<h2>Pods Count of Supply Chain K8 Cluster</h2>
<style>
table {
border-spacing: 0;
width: 80%;
border: 1px solid #ddd;
}
th, td {
text-align: left;
padding: 1px;
}
tr:nth-child(even) {
background-color: #f2f2f2
}
</style>
<BR>
<HTML><table id='myTable'>
<tr>
<th>Namespace</th>
<th>POD Name</th>
<th>Restart Count</th>
<th>Age</th>
</tr>"
tableBody=""
while read INPUT ; do
tableBody="${tableBody}<tr><td>${INPUT//,/</td><td>}</td></tr>"
done < podDetail.csv
tableEnd="</TABLE>
<script>
function sortTable() {
var table, rows, switching, i, x, y, shouldSwitch;
table = document.getElementById('myTable');
switching = true;
while (switching) {
switching = false;
rows = table.rows;
for (i = 1; i < (rows.length - 1); i++) {
shouldSwitch = false;
x = rows[i].getElementsByTagName('TD')[2];
y = rows[i + 1].getElementsByTagName('TD')[2];
if (Number(x.innerHTML) < Number(y.innerHTML)) {
shouldSwitch = true;
break;
}
}
if (shouldSwitch) {
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
}
}
}
</script>
<body onload='sortTable()'></body>
</HTML>"
emailBody=$tableStart$tableBody$tableEnd
echo ${emailBody} | mutt -e 'set content_type="text/javascript"' [email protected] -s "Info - Pods Count in SupplyChain K8 Cluster"