Beispiel #1
0
 internal void Connect()
 {
     try
     {
         upsd.Connect();
         this.Status            &= ~UPSMonStatus.COMMBAD;
         this.Status            |= UPSMonStatus.COMMOK;
         this.Device.Description = upsd.GetUPSDescription(this.Device.Name);
         upsd.SetUsername(this.Username);
         upsd.SetPassword(this.Password);
         upsd.Login(this.Device.Name);
     }
     catch (SocketException sockex)
     {
         UPSMonThreads.AppendLog("Could not connect to UPS " + this.Device.ToString() + "! " + sockex.Message);
         if (this.Status != UPSMonStatus.NOCOMMS)
         {
             this.Status &= ~UPSMonStatus.COMMOK;
             this.Status |= UPSMonStatus.COMMBAD;
         }
         upsd.Disconnect();
     }
     catch (UPSException upsex)
     {
         UPSMonThreads.AppendLog("Error on UPS " + this.Device.ToString() + "! " + upsex.Code.ToString() + ":" + upsex.Description
                                 + (String.IsNullOrEmpty(upsex.Message) ? "" : " (" + upsex.Message + ")"));
         if (this.Status != UPSMonStatus.NOCOMMS)
         {
             this.Status &= ~UPSMonStatus.COMMOK;
             this.Status |= UPSMonStatus.COMMBAD;
         }
     }
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            if ((args.Length == 0) || (args[0] == "-h") || (args[0] == "-?") || (args[0] == "--help"))
            {
                HelpText();
                return;
            }

            if (AnalyzeCommandLineParams(args) == false)
            {
                return;
            }

            UPS        target = new UPS(ups);
            UPSDClient client = new UPSDClient(target.Host);

            try
            {
                client.Connect();
                if (String.IsNullOrEmpty(authUser) == false)
                {
                    if (client.SetUsername(authUser) == false)
                    {
                        Console.WriteLine("Error: Could not set username for authentication");
                        return;
                    }
                }
                if (String.IsNullOrEmpty(authPass) == false)
                {
                    if (client.SetPassword(authPass) == false)
                    {
                        Console.WriteLine("Error: Could not set password for authentication");
                        return;
                    }
                }
                if (String.IsNullOrEmpty(variable))
                {
                    ListVariables(target, client);
                    return;
                }

                SetVariable(target, client);
            }
            catch (SocketException sockex)
            {
                Console.WriteLine("Error: " + sockex.Message);
            }
            catch (UPSException upsex)
            {
                Console.WriteLine("Error: " + upsex.Description);
            }
            finally
            {
                client.Disconnect();
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            if ((args.Length == 0) || (args[0] == "-h") || (args[0] == "-?") || (args[0] == "--help"))
            {
                HelpText();
                return;
            }

            if (AnalyzeCommandLineParams(args) == false)
            {
                return;
            }

            Console.WriteLine("ups={0}, command={1}, user={2}, password={3}, addParam={4}, listMode={5}",
                              new object[] { ups, command, authUser, authPass, addParam, listMode });

            UPS        target = new UPS(ups);
            UPSDClient client = new UPSDClient(target.Host);

            try
            {
                client.Connect();
                if (listMode)
                {
                    ListCommands(target, client);
                    return;
                }

                if (String.IsNullOrEmpty(authUser) == true)
                {
                    Console.Write("Username: "******"Error: Could not set username for authentication");
                    return;
                }

                if (String.IsNullOrEmpty(authPass) == true)
                {
                    Console.Write("Password: "******"Error: Could not set password for authentication");
                    return;
                }

                ExecuteCommand(target, client);
            }
            catch (SocketException sockex)
            {
                Console.WriteLine("Error: " + sockex.Message);
            }
            catch (UPSException upsex)
            {
                Console.WriteLine("Error: " + upsex.Description);
            }
            finally
            {
                client.Disconnect();
            }
        }