-
Notifications
You must be signed in to change notification settings - Fork 0
/
ping.php
92 lines (75 loc) · 2.47 KB
/
ping.php
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
<?php
// BY BLACKWIDO - CopyRight To https://gist.github.com/Mo45/cb0813cb8a6ebcd6524f6a36d4f8862c For WebHooks cuRL
$ping1 = "X.X.X.X"; // CHANGE BY DNS / IP
$ping2 = "X.X.X.X"; // CHANGE BY DNS / IP
$ping3 = "X.X.X.X"; // CHANGE BY DNS / IP
function ping($host, $port, $timeout) {
$tB = microtime(true);
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$fP) { return "down"; }
$tA = microtime(true);
return round((($tA - $tB) * 1000), 0)." ms";
}
$status1 = ping($ping1, 80, 10); // IP, PORT, TIMEOUT
$status2 = ping($ping2, 80, 10); // IP, PORT, TIMEOUT
$status3 = ping($ping3, 80, 10); // IP, PORT, TIMEOUT
if ($status1 != 0 ) {
$check1 = "🟢"; }
else {
$check1 = "🔴";
$status1 = "--";
}
if ($status2 != 0 ) {
$check2 = "🟢"; }
else {
$check2 = "🔴";
$status2 = "--";
}
if ($status3 != 0 ) {
$check3 = "🟢"; }
else {
$check3 = "🔴";
$status3 = "--";
}
if( ($check1 == "🔴") || ($check2 == "🔴") || ($check3 == "🔴")){
$info = "Un des serveurs ne répond pas"; // IF SOMETHING IS NOT GOOD
}
else{
$info = "Tout les services sont UP !"; // IF EVERYTHING IS OK
}
$webhookurl = "WEBHOOKURL"; // YOUR WEBHOOK URL
$time = date('H:i');
$timestamp = date("c", strtotime("now"));
// CHANGE "description": " '.$check1.' Node Jeu ['.$status1.']\n\n'.$check2.' Node Teamspeak ['.$status2.']\n\n'.$check3.' Node Web ['.$status3.']", WITH YOUR CUSTOM NODE
$json_data =
'{
"content": null,
"embeds": [
{
"title": "Status",
"description": " '.$check1.' Node Jeu ['.$status1.']\n\n'.$check2.' Node Teamspeak ['.$status2.']\n\n'.$check3.' Node Web ['.$status3.']",
"color": 5814783,
"fields": [
{
"name": "Info :",
"value": "'.$info.'"
}
],
"footer": {
"text": "By @BlackWido |Tchoin <3#2167"
},
"timestamp": "'.$timestamp.'"
}
]
}';
$ch = curl_init($webhookurl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
// If you need to debug, or find out why you can't send message uncomment line below, and execute script.
//echo $response;
curl_close($ch);