Community discussions

MikroTik App
 
djnewbie
just joined
Topic Author
Posts: 5
Joined: Sat Nov 10, 2018 9:50 am

Script Not Working

Sun Jul 25, 2021 7:14 am

i've script that monitor a PC for 30 interval, i create script below with policy Read, Write, Test. it's doesn work, which part i'm missing, please advice

:local dapod [10.10.1.2];
:if ([/ping $dapod count=10] = 10) do={
/tool fetch url="https://api.telegram.org/botxxxxxxxxxx: ... ter-Online" mode=http http-method=post keep-result=no}
else={/tool fetch url="https://api.telegram.org//botxxxxxxxxxx ... puter-Dead" mode=http http-method=post keep-result=no
/tool wol interface=ether12DAPO mac=xx:xx:xx:xx:xx:xx
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Not Working

Sun Jul 25, 2021 10:26 am

why [10.0.0.2] ?
Simply write the IP

using url "mode" and "http-method" are useless (https url = https mode, ? on ulr = get mode, post is unnecessary)

This is based on another script I have revised, send only one messages when status change.
:local host 10.0.0.2

:global hoststatus

# for test "warning unstable" set the count to 9
:local checkhost [/ping $host count=10]

:if ($checkhost = 0) do={
    :if ($hoststatus != "offline") do={
        /log error "Host $host change status from $hoststatus to offline"
        /tool fetch keep-result=no \
            url="https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat-id>&text=Komputer-Offline"
        /tool wol interface=ether12DAPO mac=xx:xx:xx:xx:xx:xx
    }
    :set hoststatus "offline"
}

:if (($checkhost > 0) && ($checkhost < 10)) do={
    :if ($hoststatus != "unstable") do={
        /log warning "Host $host change status from $hoststatus to unstable"
        /tool fetch keep-result=no \
            url="https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat-id>&text=Connection-Unstabe"
    }
    :set hoststatus "unstable"
}

:if ($checkhost = 10) do={
    :if ($hoststatus != "online") do={
        /log info "Host $host change status from $hoststatus to online"
        /tool fetch keep-result=no \
            url="https://api.telegram.org/bot<token>/sendMessage?chat_id=<chat-id>&text=Komputer-Online"
    }
    :set hoststatus "online"
}

Who is online

Users browsing this forum: No registered users and 18 guests