Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template only works with locally attached UPS #8

Open
dmth opened this issue Apr 1, 2023 · 4 comments
Open

Template only works with locally attached UPS #8

dmth opened this issue Apr 1, 2023 · 4 comments

Comments

@dmth
Copy link

dmth commented Apr 1, 2023

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.

@frhack
Copy link

frhack commented Jul 31, 2023

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

@pokdo
Copy link

pokdo commented Aug 30, 2023

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

@thenebular
Copy link

Another bump of this question.

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

@dmth
Copy link
Author

dmth commented Feb 14, 2024

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
`` 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants