Community discussions

MikroTik App
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

Display router downtime by script

Sat Jun 13, 2015 9:38 am

Hi,
I have a requirement that I want to know when router reboots, it should ECHO in LOG that when was last time router rebooted or powered off and how much time it was off by comparing it with current date/time.

Example the script should show in LOGs as following

Router last reboot (Value-A) : xx-date-time
Powered back on (Values-B): xx-date-time
Total downtime difference in hours between values A &B) : ????

I have idea that script can create a variable of last online time and update time in it after very minute, and when router reboots, it should get this value and calculate with current time value and also shows the downtime in hours (or days). I know how can I get value-a and value-B, but how to calculate difference of time in between both values to show in hours and if its in days it should days/hours ?

is it possible ?
 
wcsnet
Frequent Visitor
Frequent Visitor
Posts: 65
Joined: Mon Apr 29, 2013 12:43 pm
Location: South Africa

Display router downtime by script

Sat Jun 13, 2015 9:43 pm

Well yes you can do this but would require some scripting i would separate the values first basically get data hours minutes ect each into their own variable then convert each to seconds so if you do this for your two date time samples you should have two seconds values which you can then subtract and get the difference in seconds you can then convert the seconds back to hours


Sent from my iPhone using Tapatalk
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

Re: Display router downtime by script

Sun Jun 14, 2015 11:33 am

How can I print Specific Environment value only?
Example I have script which updates an environemtn variable with current date time, now i want to print this variable only (without other details.
for example if i try to get value from varibale it shows 3 lines and then in logs it doens't show any thing i want only VALUE

print value where name=Lastseen
user: admin
name: Lastseen
value: 13:32:47 jun/14/2015

I want to show value only
 
User avatar
aacable
Member
Member
Posts: 435
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Display router downtime by script

Sun Jun 14, 2015 11:41 am

How can I print Specific Environment value only?
Example I have script which updates an environemtn variable with current date time, now i want to print this variable only (without other details.
for example if i try to get value from varibale it shows 3 lines and then in logs it doens't show any thing i want only VALUE

print value where name=Lastseen
user: admin
name: Lastseen
value: 13:32:47 jun/14/2015

I want to show value only
Try this
:local lastseen [/system script environment get [/system script environment find name="Lastseen"] value];
:log warning $lastseen;
Result will appear in LOG window in blue color. or you can use the result in your email or whatever is required. I will post little script for you once i will be in the office
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

Re: Display router downtime by script

Mon Jun 15, 2015 12:12 pm

actually what i want is to see the last tie when was router ok. so something like lastseen value and the current one on RB. so i can calculate difference for how long the RB was down.
 
User avatar
aacable
Member
Member
Posts: 435
Joined: Wed Sep 17, 2008 11:58 am
Location: ISLAMIC Republic of PAKISTAN
Contact:

Re: Display router downtime by script

Mon Jun 15, 2015 12:15 pm

actually what i want is to see the last tie when was router ok. so something like lastseen value and the current one on RB. so i can calculate difference for how long the RB was down.
I don't know much about Routeros Scripting, but by seeing this link, http://wiki.mikrotik.com/wiki/Send_email_about_reboot , we can modify it work for your environment. but you have to create two scripts for it, one which will keep updating the date+time in a local file (to preserve it on reboot) and the second script which will trigger on next reboot.
Taking idea from the above link, modified version of that script along with the second script can be found here.
https://aacable.wordpress.com/2015/06/1 ... seen-time/
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

Re: Display router downtime by script

Mon Jun 15, 2015 1:33 pm

Don't know how , but it worked perfectly :) Thank You All ! :)
 
cicserver
Member
Member
Topic Author
Posts: 303
Joined: Sun Jul 24, 2011 12:04 pm

Re: Display router downtime by script

Tue Jun 30, 2015 6:18 am

How can I display total time of downtime? example above script shows only from - till time, how can i show lets say "router was down for 36 hours" or "router was down for 1 day 16 hours"?

Who is online

Users browsing this forum: Semrush [Bot] and 21 guests