Zabbix-NUT-Template icon indicating copy to clipboard operation
Zabbix-NUT-Template copied to clipboard

Template only works with locally attached UPS

Open dmth opened this issue 1 year ago • 4 comments

Today I figured out the template only works with locally attached UPSes.

If NUT is used in netclient mode, the script ups_status.sh has to be extended with the hostname of the nut-server at three locations.

dmth avatar Apr 01 '23 15:04 dmth

Today I figured out the template only works with locally attached UPSes.

If NUT is used in netclient mode, the script ups_status.sh has to be extended with the hostname of the nut-server at three locations.

I have the same issue, can you please show me how to change the script in order to use It in netclient mode ?

Thanks

frhack avatar Jul 31 '23 13:07 frhack

Bump of this same question. Can you give details on the script edit for using netclient mode? Thanks

pokdo avatar Aug 30 '23 15:08 pokdo

Another bump of this question.

How do we add the hostname to ups_status.sh in that it pulls the hostname as a variable.

thenebular avatar Jan 29 '24 20:01 thenebular

ooooh, sorry guys I didn't check on my GH notifications for a long time. I didn't intend to keep you hanging. Apparently I figured it out but i never supplied a solution. Here's my patch for the problem. You need to replace YOURHOSTSIP with the IP of your host. If you are not familiar with the patch format: Replace the lines beginning with - by the lines beginning with + in your ups_status.sh and add the line below ups=$1

diff --git a/sh/ups_status.sh b/sh/ups_status.sh
index f450927..396a78e 100755
--- a/sh/ups_status.sh
+++ b/sh/ups_status.sh
@@ -1,12 +1,13 @@
 #!/bin/bash
 
 ups=$1
+host=YOURHOSTSIP # this should somehow be set by a Zabbix-Macro.
 
 if [ $ups = ups.discovery ]; then
 
     echo -e "{\n\t\"data\":["
     first=1
-    /bin/upsc -l 2>&1 | grep -v SSL | while read discovered ; do
+    /bin/upsc -l $host 2>&1 | grep -v SSL | while read discovered ; do
         if [ $first -eq 0 ]; then
             echo -e ","
         fi
@@ -19,7 +20,7 @@ else
 key=$2
 
 if [[ $key = ups.status ]]; then
-	state=`/bin/upsc $ups $key 2>&1 | grep -v SSL`
+	state=`/bin/upsc $ups@$host $key 2>&1 | grep -v SSL`
 	case "$state" in
 		"OL")		echo 1 ;; #'On line (mains is present)' ;;
 		"OB")		echo 2 ;; #'On battery' ;;
@@ -38,7 +39,7 @@ if [[ $key = ups.status ]]; then
 		* )		echo 0 ;; #'unknown state' ;;
 	esac
 else
-	/bin/upsc $ups $key  2>&1 | grep -v SSL
+	/bin/upsc $ups@$host $key  2>&1 | grep -v SSL
 fi
 
 fi
`` 

dmth avatar Feb 14 '24 20:02 dmth