Blob Blame Raw
diff -up nut-2.6.5/scripts/python/app/NUT-Monitor.unreachable nut-2.6.5/scripts/python/app/NUT-Monitor
--- nut-2.6.5/scripts/python/app/NUT-Monitor.unreachable	2012-07-31 19:38:56.000000000 +0200
+++ nut-2.6.5/scripts/python/app/NUT-Monitor	2013-01-07 18:04:26.532531441 +0100
@@ -674,6 +674,11 @@ class interface :
             self.gui_status_notification( _("Device '%s' not found on server") % self.__current_ups, "warning.png" )
             return
 
+        if not self.__ups_handler.CheckUPSAvailable( self.__current_ups ): 
+            self.gui_status_message( _("UPS '{0}' is not reachable").format( self.__current_ups ) )
+            self.gui_status_notification( _("UPS '{0}' is not reachable").format( self.__current_ups ), "warning.png" )
+            return
+
         self.__connected = True
         self.__widgets["ups_connect"].hide()
         self.__widgets["ups_disconnect"].show()
diff -up nut-2.6.5/scripts/python/module/PyNUT.py.unreachable nut-2.6.5/scripts/python/module/PyNUT.py
--- nut-2.6.5/scripts/python/module/PyNUT.py.unreachable	2012-07-31 19:38:56.000000000 +0200
+++ nut-2.6.5/scripts/python/module/PyNUT.py	2013-01-07 17:41:26.548440712 +0100
@@ -158,6 +158,20 @@ available vars.
 
         return( ups_vars )
 
+    def CheckUPSAvailable( self, ups="") :
+        """ Check whether UPS is reachable
+
+Just tries to contact UPS with safe command.
+The result is True (rechable) or False (unreachable)
+        """
+        self.__srv_handler.write( "LIST CMD %s\n" % ups )
+        result = self.__srv_handler.read_until( "\n" )
+        if result != "BEGIN LIST CMD %s\n" % ups :
+            return False
+
+        self.__srv_handler.read_until( "END LIST CMD %s\n" % ups )
+        return True
+
     def GetUPSCommands( self, ups="" ) :
         """ Get all available commands for the specified UPS