Hello,
To monitor my home server’s proper functioning, I have set up monitoring with Netwatch using the https-get type.
Not understanding why the alarm is triggered, the script ( see below) runs when the alarm is generated.
So often, but not regularly, the alarm is triggered, and it’s the tcpConnectTime parameter collected with this command ([tonsec [/tool netwatch get terra tcp-connect-time ]]) that is found to be zero.
Less than a minute later, the alarm is cleared with a normal tcpConnectTime value.
What I don’t understand is that this parameter is not supposed to be a triggering element in Netwatch with the https-get parameter. See the doc: https://help.mikrotik.com/docs/spaces/ROS/pages/8323208/Netwatch#Netwatch-HTTP-GET%2FHTTPS-GETprobepass%2Ffailcriteria
Any ideas?
Config of netwatch :
/tool netwatch export where host=192.168.88.200
# 2025-02-06 08:54:25 by RouterOS 7.17.1
# model = RBD52G-5HacD2HnD
# serial number = B4xxxxxxx
/tool netwatch
add comment="Verification Terra repond aux requetes https" disabled=no down-script=terra_offline host=192.168.88.200 http-codes="" interval=1m name=terra port=\
443 src-address=192.168.88.1 startup-delay=0s test-script="\
\n" thr-http-time=200ms thr-tcp-conn-time=20s type=https-get up-script=terra_online
script : script=terra_offline
# Extract Netwatch stats for the "terra" test
# Parse the stats to extract the required variables
:local tcpConnectTime ([tonsec [/tool netwatch get terra tcp-connect-time ]] )
:local httpStatusCode ([/tool netwatch get terra http-status-code ])
:local httpRespTime ( [/tool netwatch get terra http-resp-time ])
# Log the extracted variables for debugging
:log warning ("TERRA OFF line")
:log warning ("TCP Connect Time: $tcpConnectTime")
:log warning ("HTTP Status Code: $httpStatusCode")
:log warning ("HTTP Response Time ms: $httpRespTime")
# Initialize the retry counter
:local retryCount 0
# Check if tcpConnectTime is zero and retry if necessary
:while ($tcpConnectTime = 0 and $retryCount < 2) do {
:delay 10s
:set retryCount ($retryCount + 1)
:local tcpConnectTime ([tonsec [/tool netwatch get terra tcp-connect-time ]] )
:log warning ("Retrying... TCP Connect Time: $tcpConnectTime, Attempt: $retryCount")
# Check again if tcpConnectTime is positive after retry
:if ($tcpConnectTime > 0) do {
:log warning ("tcpConnectTime is positive after retry. Exiting the script.")
:return
}
}
# tcpconnecttime confirmé à zero
# Split the time string into components
:local hours ([ :pick $httpRespTime 0 2 ])
:local minutes ([ :pick $httpRespTime 3 5 ])
:local seconds ([ :pick $httpRespTime 6 8 ])
:local microseconds ([ :pick $httpRespTime 11 16 ])
# Convert each component to milliseconds
:local hoursInMs ($hours * 3600000)
:local minutesInMs ($minutes * 60000)
:local secondsInMs ($seconds * 1000)
:local microsecondsInMs ($microseconds)
# Sum all components to get the total milliseconds
:local totalMs ($hoursInMs + $minutesInMs + $secondsInMs + $microsecondsInMs)
# Construct the alert message
:local alertMessage ("Terra is OFF line from MK. TCP Connect Time: $tcpConnectTime, HTTP Status Code: $httpStatusCode, HTTP Response Time (ms): $totalMs")
# Send the alert using /tool fetch
/tool fetch url="https://ntfy.sh/xxxxxxx" mode=https http-method=post http-data=$alertMessage http-header-field="Priority:5, Tags:sos, Title:### ALERTE ###, Tags:sos"
Log when alarm is trigerred :
025-02-06T08:46:57.019327+01:00 mikrotik script,warning TERRA OFF line
2025-02-06T08:46:57.019791+01:00 mikrotik script,warning TCP Connect Time: 0
2025-02-06T08:46:57.020134+01:00 mikrotik script,warning HTTP Status Code: 200
2025-02-06T08:46:57.020581+01:00 mikrotik script,warning HTTP Response Time ms: 00:00:00.003371
2025-02-06T08:47:07.022830+01:00 mikrotik script,warning Retrying... TCP Connect Time: 0, Attempt: 1
2025-02-06T08:47:17.025749+01:00 mikrotik script,warning Retrying... TCP Connect Time: 0, Attempt: 2
2025-02-06T08:47:56.111672+01:00 mikrotik script,warning TERRA ONline
2025-02-06T08:47:56.112094+01:00 mikrotik script,warning TCP Connect Time: 544000
2025-02-06T08:47:56.112579+01:00 mikrotik script,warning HTTP Status Code: 200
2025-02-06T08:47:56.112944+01:00 mikrotik script,warning HTTP Response Time ms: 00:00:00.003542