-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload_cachet
137 lines (113 loc) · 3.82 KB
/
load_cachet
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# This file is part of a collection of bash scripts written and used by me which may be handy in server administration.
#
# (c) Corrado Mulas <tlc@mulas.me>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
LOAD=$(uptime | awk -F'[a-z]:' '{ print $2}' | cut -f2 -d " " | sed 's/.$//' | tr -s , .)
#TIMEST=date '+%F %T'
CACHET_KEY="your_api_key"
CACHET_URL_M1="https://your-host/api/v1/metrics/1/points"
CACHET_URL_C1="https://your-host/api/v1/components/1"
STATUS_C1="0"
generate_post_data()
{
cat <<EOF
{"value": ${LOAD}}
EOF
}
#METRICS
curl --silent -H "Content-Type: application/json;" POST -H "X-Cachet-Token: ${CACHET_KEY}" --url ${CACHET_URL_M1} --data '{"value": '${LOAD}'}'
#COMPONENTS
#curl --silent -H "Content-Type: application/json;" DELETE -H "X-Cachet-Token: ${CACHET_KEY}" --url ${CACHET_URL_C1} --data '{"value": '${STATUS_C1}'}'
#ASTERISK #2
if pgrep -x "asterisk" > /dev/null && pgrep -x "safe_asterisk" > /dev/null
then
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/2 \
-d '{"status":1}'
else
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/2 \
-d '{"status":4}'
fi
#EMBY #17
if pgrep -x "EmbyServer" > /dev/null
then
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/17 \
-d '{"status":1}'
else
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/17 \
-d '{"status":4}'
fi
LOAD_TIME_C17=$(/a2loadtime.sh your_emby_host 1 | grep "min=" | awk '{print $5}'| sed 2,2d | head -c-2 | sed 's/min=//' | tr ',' '.')
BC_COMP_C17=$(echo "${LOAD_TIME_C17}>1" | bc)
if [ "${BC_COMP_C17}" == 1 ]
then
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/17 \
-d '{"status":2}'
fi
#curl -H "Content-Type:application/json" \
# -H "X-Cachet-Token: ${CACHET_KEY}" \
# -X PUT https://your-host/api/v1/components/3 \
# -d '{"status":0}'
#echo ${LOAD}
#DOVECOT #16
if pgrep -x "dovecot" > /dev/null && nc -w 2 -z "imap.mulas.me" 143
then
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/16 \
-d '{"status":1}'
else
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/16 \
-d '{"status":4}'
fi
#POSTFIX #6
#/usr/lib/postfix/sbin/master -w
#qmgr -l -t unix -u
#tlsmgr -l -t unix -u -c
#pickup -l -t unix -u -c
#anvil -l -t unix -u -c
if pgrep -x "master" > /dev/null && pgrep -x "qmgr" > /dev/null && pgrep -x "tlsmgr" > /dev/null && pgrep -x "pickup" > /dev/null && nc -w 2 -z "smtp.example.com" 25
then
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/6 \
-d '{"status":1}'
else
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/6 \
-d '{"status":4}'
fi
#ASTERISK IAX TRUNKS INTERCONNECTION #21
serviceIsRunning=false
var1=$(/usr/sbin/asterisk -rx "iax2 show peers" |grep "TRUNK_NAME" |awk '{print $8}'| sed 2,2d)
var2=$(echo $data | awk '{print $2}')
if [ "$var1" == OK ]
then
serviceIsRunning=true
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/21 \
-d '{"status":1}'
fi
if [ $serviceIsRunning == false ]
then
curl -H "Content-Type:application/json" \
-H "X-Cachet-Token: ${CACHET_KEY}" \
-X PUT https://your-host/api/v1/components/21 \
-d '{"status":4}'
fi