Community discussions

MikroTik App
 
xcom
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 80
Joined: Sat Jul 05, 2014 8:59 pm

Feature Request: NUT Client

Fri Nov 07, 2014 5:14 am

Is it possible to have an apk for a nut client/server?
This could be very beneficial to the community.

Regards!
 
User avatar
macgaiver
Forum Guru
Forum Guru
Posts: 1768
Joined: Wed May 18, 2005 5:57 pm
Location: Sol III, Sol system, Sector 001, Alpha Quadrant

Re: Feature Request: NUT Client

Fri Nov 07, 2014 8:10 am

link to RFC or other standard would be useful :) it is first time i hear about something like that and searching for "nut" comes with lots of "different" results :)
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Feature Request: NUT Client

Fri Nov 07, 2014 8:14 am

Having network attached ups it provides snmp. Why to implement nut it it the router?
 
User avatar
docmarius
Forum Guru
Forum Guru
Posts: 1224
Joined: Sat Nov 06, 2010 12:04 pm
Location: Timisoara, Romania
Contact:

Re: Feature Request: NUT Client

Fri Nov 07, 2014 8:55 am

+1

@macgaiver: http://www.networkupstools.org/

I had put this in discussion some time time ago:
http://forum.mikrotik.com/viewtopic.php?f=1&t=48762

But it seems that everyone understands to implement the NUT server, not the client. But you are right, nut may offer also snmp services through the nut-snmpagent wrapper.

Again, it is about the nut client. The possibility to connect to another system running the nut daemon to interrogate the UPS status and take decisions based on that data. No one said to implement nut on the router.

@jarda: having a network attached UPS starts with the false assumption that you have one.

And while supporting the APC protocol is nice, most of the UPSes out there are not APC compatible.
E.g. the blazer protocol is used by a lot of manufacturers (Ablerex, ActivePower, ARTronic, ATEK, some Belkins, Borri, Cover, Dynamix, Effekta, Ever, Fenton, GE Digital Energy, Gtec, Infosec, Ippon, Kolff, Krauler, Maxxtro, Microline, Mustek, Plexus, Powerex, Powerguard, PowerWalker, Soyntec, Sven, some Sweex, Sysgration, Tecnoware, Trust, Unitek, some Upsonic and a lot of others).
This protocol is of course not supported by MT, as if APC is the only "real" UPS manufacturer. And here comes nut into play, running on another system and offering a uniform network approach for EVERY UPS.
But for this, a network client on the router is needed.
And this is what xcom has asked.
 
xcom
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 80
Joined: Sat Jul 05, 2014 8:59 pm

Re: Feature Request: NUT Client

Fri Nov 07, 2014 4:40 pm

+1

@macgaiver: http://www.networkupstools.org/

I had put this in discussion some time time ago:
http://forum.mikrotik.com/viewtopic.php?f=1&t=48762

But it seems that everyone understands to implement the NUT server, not the client. But you are right, nut may offer also snmp services through the nut-snmpagent wrapper.

Again, it is about the nut client. The possibility to connect to another system running the nut daemon to interrogate the UPS status and take decisions based on that data. No one said to implement nut on the router.

@jarda: having a network attached UPS starts with the false assumption that you have one.

And while supporting the APC protocol is nice, most of the UPSes out there are not APC compatible.
E.g. the blazer protocol is used by a lot of manufacturers (Ablerex, ActivePower, ARTronic, ATEK, some Belkins, Borri, Cover, Dynamix, Effekta, Ever, Fenton, GE Digital Energy, Gtec, Infosec, Ippon, Kolff, Krauler, Maxxtro, Microline, Mustek, Plexus, Powerex, Powerguard, PowerWalker, Soyntec, Sven, some Sweex, Sysgration, Tecnoware, Trust, Unitek, some Upsonic and a lot of others).
This protocol is of course not supported by MT, as if APC is the only "real" UPS manufacturer. And here comes nut into play, running on another system and offering a uniform network approach for EVERY UPS.
But for this, a network client on the router is needed.
And this is what xcom has asked.
Yes this is right! Thanks docmarius! :D
All my servers/nas/workstation connect to my NUT server and when we get a power outage they all shutdown (Different times for each) base on my configs.
Having this on my Mikrotik allows to safely shutdown the switch without having to run a dedicated serial cable to it or for that matter a dedicated UPS.
I have a whole office UPS and connects to my electrical breaker unit.
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Feature Request: NUT Client

Fri Nov 07, 2014 5:15 pm

How do you start remotely your mikrotik devices when the outage is gone if you shut down them before?
 
xcom
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 80
Joined: Sat Jul 05, 2014 8:59 pm

Re: Feature Request: NUT Client

Fri Nov 07, 2014 5:31 pm

How do you start remotely your mikrotik devices when the outage is gone if you shut down them before?
It all depends how your ups is configured along with NUT. In my case. I have my system configured via nut to shutdown when the ups reaches critical stages.
Once nut knows all of the systems are down the UPS shutsdown and wait for electrical power to be restored. Once electrical power is restored the battery waits 10Min before it supply's power to the sockets. Once the sockets are energized all systems power up just like if you where connecting your power cable behind your switch... It just turns on.

For my servers I have them enable to comeback online when power is restore. Other devices require manual innervation and I turn them on via WOL.
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Feature Request: NUT Client

Fri Nov 07, 2014 5:41 pm

This is smart. Thanks for answer. But doesn't it just prolonging the outage time? And what if not all devices went down correctly? Do you still recycle the power? Nut client could be useful in some cases, I agree. But I still would rather see mikrotik focusing on errors corrections then implementing such marginal features.
 
xcom
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 80
Joined: Sat Jul 05, 2014 8:59 pm

Re: Feature Request: NUT Client

Fri Nov 07, 2014 6:06 pm

This is smart. Thanks for answer. But doesn't it just prolonging the outage time? And what if not all devices went down correctly? Do you still recycle the power? Nut client could be useful in some cases, I agree. But I still would rather see mikrotik focusing on errors corrections then implementing such marginal features.
No solution is perfect. :D
The 10Min wait time is a buffer to charge the battery enough in case of another outage, This gives time for NUT to shutdown the systems again if need it. Technically yes it prolongs the outage but I rather have a buffer for things to shutdown cleanly than not having it.... :D
I have not had a problem where all devices have shutdown uncleanly though I am ready for such issues... Backups =]
 
iScape
Frequent Visitor
Frequent Visitor
Posts: 84
Joined: Sun Dec 23, 2012 1:23 am

Re: Feature Request: NUT Client

Mon Nov 17, 2014 10:57 pm

+1 for xcom request
 
User avatar
111111
Member Candidate
Member Candidate
Posts: 195
Joined: Thu Oct 05, 2006 1:39 am
Location: BG,SOFIA

Re: Feature Request: NUT Client

Mon Dec 29, 2014 3:40 am

/system ups print oid
Ros 6.15
 model=.1.3.6.1.2.1.33.1.1.2 
 version=.1.3.6.1.2.1.33.1.1.3 
 status=.1.3.6.1.2.1.33.1.2.1 
 remaining=.1.3.6.1.2.1.33.1.2.3 
 battery-charge=.1.3.6.1.2.1.33.1.2.4 
 voltage=.1.3.6.1.2.1.33.1.2.5 
 temperature=.1.3.6.1.2.1.33.1.2.7 
ROS 6.24
 model=.1.3.6.1.2.1.33.1.1.2 
 version=.1.3.6.1.2.1.33.1.1.3 
 status=.1.3.6.1.2.1.33.1.2.1 
 remaining=.1.3.6.1.2.1.33.1.2.3 
 battery-charge=.1.3.6.1.2.1.33.1.2.4 
 voltage=.1.3.6.1.2.1.33.1.2.5 
 temperature=.1.3.6.1.2.1.33.1.2.7 
 replace-battery=.1.3.6.1.2.1.33.1.6.2.1.2.1 
 low-battery=.1.3.6.1.2.1.33.1.6.2.1.2.2 
 overload=.1.3.6.1.2.1.33.1.6.2.1.2.3 
 line-voltage=.1.3.6.1.2.1.33.1.3.3.1.3 
 frequency=.1.3.6.1.2.1.33.1.3.3.1.2 
 output-voltage=.1.3.6.1.2.1.33.1.4.4.1.2 
 load=.1.3.6.1.2.1.33.1.4.4.1.5
but the problem is with real situation
snmpwalk -v 1 -c public 10.0.0.1 .1.3.6.1.2.1.33.1
iso.3.6.1.2.1.33.1.1.2.0 = STRING: "Smart-UPS SC620 "
iso.3.6.1.2.1.33.1.1.3.0 = STRING: "726.1.I"
iso.3.6.1.2.1.33.1.2.1.0 = INTEGER: 2
iso.3.6.1.2.1.33.1.2.3.0 = INTEGER: 660
iso.3.6.1.2.1.33.1.2.4.0 = INTEGER: 100
iso.3.6.1.2.1.33.1.2.5.0 = INTEGER: 13
iso.3.6.1.2.1.33.1.2.7.0 = INTEGER: 0
iso.3.6.1.2.1.33.1.3.2.0 = INTEGER: 1
iso.3.6.1.2.1.33.1.3.3.1.2.1 = INTEGER: 5000
iso.3.6.1.2.1.33.1.3.3.1.3.1 = INTEGER: 231
iso.3.6.1.2.1.33.1.4.3.0 = INTEGER: 1
iso.3.6.1.2.1.33.1.4.4.1.2.1 = INTEGER: 231
iso.3.6.1.2.1.33.1.4.4.1.5.1 = INTEGER: 58
iso.3.6.1.2.1.33.1.6.1.0 = Gauge32: 0
what are this zeroes on end
snmpget -v 1 -c public 10.0.0.1 .1.3.6.1.2.1.33.1.2.3
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: iso.3.6.1.2.1.33.1.2.3

snmpget -v 1 -c public 10.0.0.1 .1.3.6.1.2.1.33.1.2.3.0
iso.3.6.1.2.1.33.1.2.3.0 = INTEGER: 600
is this a bug
 
benoga
just joined
Posts: 13
Joined: Wed Mar 09, 2016 7:50 am

Re: Feature Request: NUT Client

Sat Apr 30, 2016 10:41 am

+1

NUT Client to Shutdown the Mikrotik would be very nice!
 
nickjail
just joined
Posts: 15
Joined: Mon Feb 17, 2014 9:26 pm

Re: Feature Request: NUT Client

Mon May 02, 2016 12:35 am

+1
Must have
 
dgcapel
just joined
Posts: 9
Joined: Tue Jan 26, 2016 6:03 pm
Location: Murcia, Spain
Contact:

Re: Feature Request: NUT Client

Thu Jun 02, 2016 6:49 pm

Yes, I'm searching about this function in Mikrotik. +1
 
korniza
newbie
Posts: 26
Joined: Fri Jan 06, 2012 4:05 pm

Re: Feature Request: NUT Client

Sat Jun 04, 2016 5:42 pm

+1
ups status for network rerouting scenarios
 
nickjail
just joined
Posts: 15
Joined: Mon Feb 17, 2014 9:26 pm

Re: Feature Request: NUT Client

Sun Jul 24, 2016 2:09 pm

+1
NUT is useful
 
Zorro
Long time Member
Long time Member
Posts: 675
Joined: Wed Apr 16, 2014 2:43 pm

Re: Feature Request: NUT Client

Sat Aug 06, 2016 2:07 am

but it never really become "standard", yet. right?
so its not really good idea to push harder for proprietary stuff that replace some of really Standard things, even if they intend to "converge" or "simplify", "unify" or whatever of them they doing.
its like https://xkcd.com/927/ or something.

p.s.
jebus, what i name. initially i thouigh that was "NUT" container from (almost abandoned, sadly)Snow video compression codec and that resulted in insta-headache(if you read its code you know why.
(things like shrodinger, av1, daala, thor and more bogus things like upcoming/speculated theora encoders - are Way better documented and had well-written code in 70-90% portions of it) ;)
Last edited by Zorro on Sat Aug 06, 2016 5:16 am, edited 1 time in total.
 
IntrusDave
Forum Guru
Forum Guru
Posts: 1286
Joined: Fri May 09, 2014 4:36 am
Location: Rancho Cucamonga, CA

Re: Feature Request: NUT Client

Sat Aug 06, 2016 2:14 am

NUT would be nice. My Eaton Power Systems all have NUT servers embedded.
However - the MikroTik guys have stated a few times that there is no problem with RouterOS losing power, it does not hurt them.
 
Zorro
Long time Member
Long time Member
Posts: 675
Joined: Wed Apr 16, 2014 2:43 pm

Re: Feature Request: NUT Client

Sat Aug 06, 2016 5:14 am

NUT would be nice. My Eaton Power Systems all have NUT servers embedded.
However - the MikroTik guys have stated a few times that there is no problem with RouterOS losing power, it does not hurt them.
some folks i worked with - would go for anything "NUT"-labeled just "for fun", because name itself ;)
atleast you always can say "WUT? NUT!" to you boss in any case ;)
 
IntrusDave
Forum Guru
Forum Guru
Posts: 1286
Joined: Fri May 09, 2014 4:36 am
Location: Rancho Cucamonga, CA

Re: Feature Request: NUT Client

Sat Aug 06, 2016 6:20 am

I have a tech that loves to point out that any updates always seem to "bust a nut".
 
User avatar
docmarius
Forum Guru
Forum Guru
Posts: 1224
Joined: Sat Nov 06, 2010 12:04 pm
Location: Timisoara, Romania
Contact:

Re: Feature Request: NUT Client

Sat Aug 06, 2016 4:41 pm

NUT would be nice. My Eaton Power Systems all have NUT servers embedded.
However - the MikroTik guys have stated a few times that there is no problem with RouterOS losing power, it does not hurt them.
Then why did they put ANY ups support into the routers? Was it just for fun?

BTW, it is not necessarily about powering down the router. It could be about reconfiguring the network by script into a backup/power down configuration. e.g. not all setups use a single power line, and they may down a server or two with rerouting...
Remember that bypass switch on the RB1100 doing similar stuff?
 
IntrusDave
Forum Guru
Forum Guru
Posts: 1286
Joined: Fri May 09, 2014 4:36 am
Location: Rancho Cucamonga, CA

Re: Feature Request: NUT Client

Sat Aug 06, 2016 5:51 pm

Oh, I agree complete. I was just restarted with the support guys said.
 
JorgeAmaral
Trainer
Trainer
Posts: 199
Joined: Wed Mar 04, 2009 11:53 pm
Location: /ip route add type=blackhole

Re: Feature Request: NUT Client

Wed Mar 14, 2018 3:07 am

+1

For remote sites this would be awesome, one mikrotik acting as nut server and a couple of other devices with nut clients.
 
iScape
Frequent Visitor
Frequent Visitor
Posts: 84
Joined: Sun Dec 23, 2012 1:23 am

Re: Feature Request: NUT Client

Thu Oct 18, 2018 12:50 am

+1

Has anyone figured out how to script MT in a way, that if APC (attached via UBS) goes on battery, then MT notifies all other network devices about power down?
 
User avatar
inteq
Member
Member
Posts: 427
Joined: Wed Feb 25, 2015 8:15 pm
Location: Romania

Re: Feature Request: NUT Client

Sat Mar 30, 2019 5:56 am

+ for MT NUT client support
 
nwa
newbie
Posts: 29
Joined: Sun Aug 17, 2014 3:02 pm

Re: Feature Request: NUT Client

Sun Nov 17, 2019 9:25 pm

+1

pro nut-client !
because... the router board suck the battery totally empty on a long power failure
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 21242
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Feature Request: NUT Client

Mon Nov 18, 2019 12:00 am

Haha I am the manual NUT in the family.
Is this another item to move to the raspberry pi?
 
User avatar
webrunner
just joined
Posts: 4
Joined: Sun Apr 24, 2022 6:00 pm
Location: Poland
Contact:

Re: Feature Request: NUT Client

Fri May 20, 2022 12:09 am

Hi,

You can install a nut on a raspberry pi and connect a UPS through usb to raspberry. Video: https://www.youtube.com/watch?v=vyBP7wpN72c&t=1645s

If a help is needed with any part, do not hesitate to ask.

I was able to set up Home assistant as the docker container on a raspberry Pi and add my Green Cell UPS there - actually Home Assistant detected it automatically. :) I see basic information like load, power etc. I had to do that because I am using AdGuard Home on a raspberry and I was not able to run it together. The Home Assistant is working locally so, I had to create a ssh tunnel to be able to access it from my laptop.

I had to change the driver to nutdrv_qx and modify a little bit the ups.conf to be able to work with the mentioned UPS. Finally I have it working and the Raspberry Pi is shutting down as it should. Early shutdown I set to 180 seconds. Now it is time to write a bash script that will log into Mikrotik router and perform the shutdown command before the raspberry will shut down. I will use a bash script that I tested on my Mikrotik hap ac2.
#!/bin/bash
# The result of the script execution is recorded in the mikrotik.log located in the /root directory.
LOG_FILE=/root/mikrotik.log
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>${LOG_FILE} 2>&1
data=$( date +"%Y-%m-%d %H:%M:%S" )
nutlog=/var/log/nut.log
if [ "`grep "Mikrotik" "$nutlog"`" ]; then
        echo "$data -> Mikrotik router will go down."
        echo "UPS is down!" | mail -s "UPS ALERT DOWN" admin@example.com -A /root/mikrotik.log
        echo "UPS is down!" | mail -s "UPS ALERT DOWN" youremail@gmail.com -A /root/mikrotik.log
        rm -f $nutlog
        touch $nutlog
        chown root:adm $nutlog
        chmod 640 $nutlog
        systemctl restart rsyslog
        sshpass -f /root/creds ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o CheckHostIP=no -p 2244 nut@192.168.88.1 "/system shutdown; /y; /quit;"
        exit
else
        echo "$data -> Mikrotik router will remain powered on."
        exit
fi

Of course sshpass has to be installed with the below command
sudo apt install sshpass
-p 2244 is a nonstandard ssh port

I created a nut user on a mikrotik and additionally tested it with RSA keys without a passphrase what in LAN is let's say secure enough. All you have to do is to save private and public key in openSSH format, but not the newest one, but instead the standard format - hope I explained it well, just because Puttygen allow syou to save the RSA key in new openSSH format. Anyway you have to upload the private key into the Files in mikrotik, and then in system - users section im port the key for a user. But you can also just use ordinary password with sshpass as I did in the password. If yopu want use RSA, you have to remove this from bash script: spawn sshpass -f /root/creds

Then you have to add the below line to crontab for root account but it can be also a pi user and it will run every two minutes.
*/2 * * * * root /root/mikrotik.sh
*/2 * * * * pi /home/pi/mikrotik.sh
for the pi user you have to add sudo before each command in the above bash script

The default system logger is rsyslog. Add the following to /etc/rsyslog.d/99-nut.conf
:syslogtag,contains,"upsmon" /var/log/nut.log
:syslogtag,contains,"nut" /var/log/nut.log
:syslogtag,contains,"upssched" /var/log/nut.log
Then perform the below commands:
touch /var/log/nut.log
chown root:adm /var/log/nut.log
chmod 640 /var/log/nut.log
systemctl restart rsyslog
All the nut logs will go there.

In the file /etc/nut/upssched.conf I defined below actions
AT ONBATT * START-TIMER onbatt 300
AT ONLINE * CANCEL-TIMER onbatt online
AT ONBATT * START-TIMER earlyshutdown 180
AT ONLINE * CANCEL-TIMER earlyshutdown
AT LOWBATT * START-TIMER shutdowncritical 30
AT ONLINE * CANCEL-TIMER shutdowncritical
AT COMMBAD * START-TIMER commbad 30
AT COMMOK * CANCEL-TIMER commbad commok
AT REPLBATT * EXECUTE replacebatt
And the /bin/upssched-cmd file contains the below:
case $1 in
       onbatt)
          logger -t upssched-cmd "The UPS is on battery"
          ;;
       online)
          logger -t upssched-cmd "The UPS is back on power"
          ;;
       commbad)
       logger -t upssched-cmd "The server lost communication with UPS"
          ;;
       commok)
          logger -t upssched-cmd "The server re-establish communication with UPS"
          ;;
       earlyshutdown)
          logger -t upssched-cmd "UPS on battery too long, forced Mikrotik shutdown"
          ;;
       shutdowncritical)
          logger -t upssched-cmd "UPS on battery critical, forced shutdown"
          /usr/sbin/upsmon -c fsd
          ;;
       upsgone)
          logger -t upssched-cmd "The UPS has been gone for awhile"
          ;;
       replacebatt)
          logger -t upssched-cmd "The UPS needs new battery"
          ;;
       *)
          logger -t upssched-cmd "Unrecognized command: $1"
          ;;
 esac
My bash script catches the Mikrotik phrase from the log. I had to test it to be sure for 100% it is working as expected.

Sending e-mails

Log as root with the below command
sudo -i
Install th below tools:
apt install ssmtp mailutils
Edit configurtation file, to be able to send e-mails with gmail:
nano /etc/ssmtp/ssmtp.conf
Set as below:
root=postmaster
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=yourhostname ##for example raspberrypi
UseSTARTTLS=YES
AuthUser=youremailaddress@gmail.com
AuthPass=google_mail_application_password
FromLineOverride=YES
Important: Not the mail password for your gmail. So, you have to generate application password. Guide: https://support.google.com/mail/answer/185833?hl=en

Create emailnotify.sh in /root
nano emailnotify.sh
Put into the file the below:
#!/bin/bash

sleep 60

IP=`hostname -i`
# Or you can comment the above and uncomment the below. In my case it presented the localhost IP address instead the IP from eth0 interface
# IP=`echo $(ifconfig eth0 | grep 'inet' | cut -d: -f2 | awk '{ print $2}')`
HOSTNAME=`hostname -f`
echo "$HOSTNAME online.  IP address: $IP" > /root/email.txt
echo >> /root/email.txt
date >> /root/email.txt

mail -s "$HOSTNAME online" -r raspberrypi@localhost yourmail@example.com < /root/email.txt
mail -s "$HOSTNAME online" -r raspberrypi@localhost yourmail@gmail.com < /root/email.txt

rm -rf /root/email.txt
Then set it as executable
chmod +x emailnotify.sh
Then edit crontab
crontab -e
and add the below entry:
@reboot /root/emailnotify.sh
Now if the UPS will go down you will be notified and also when the raspberry pi will boot up.
Last edited by webrunner on Tue Jul 12, 2022 4:51 pm, edited 38 times in total.
 
User avatar
webrunner
just joined
Posts: 4
Joined: Sun Apr 24, 2022 6:00 pm
Location: Poland
Contact:

Re: Feature Request: NUT Client

Fri May 20, 2022 12:25 am

Haha I am the manual NUT in the family.
Is this another item to move to the raspberry pi?
See my post how I performed it. Hope you will enjoy. Let me know of some video tutorial will be needed - I can make one to present how particular steps have been done.

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], sindy and 62 guests