Ejemplo n.º 1
0
        //This method is a collection of unit test assertions.
        static void TestDriver()
        {
            Model AtwaterMonitorModel = new Model();
            float epsilon             = 0.0000001f;
            UPS   n = new UPS("UPS_01", @"10.10.41.41");

            n.AddAmbientTemperatureReading(89f, DateTime.Now);
            n.AddAmbientTemperatureReading(95f, DateTime.Now);
            n.AddAmbientTemperatureReading(87f, DateTime.Now);
            n.AddAmbientTemperatureReading(78f, DateTime.Now);
            AtwaterMonitorModel.AddNetworkDevice(n);

            UPS n2 = new UPS("UPS_03", @"10.10.102.41");

            n2.AddAmbientTemperatureReading(89f, DateTime.Now);
            n2.AddAmbientTemperatureReading(95f, DateTime.Now);
            n2.AddAmbientTemperatureReading(87f, DateTime.Now);
            n2.AddAmbientTemperatureReading(87.8f, DateTime.Now);

            AtwaterMonitorModel.AddNetworkDevice(n2);

            //Tests for the UPS and NetworkDevice Classes
            Debug.Assert(n.Hostname == "UPS_01", "FAILED: UPS.Constructor/Getter - Hostname");
            Debug.Assert(n.IPAddress == @"10.10.41.41", "FAILED: UPS.Constructor/Getter - IPAddress");
            Debug.Assert(n.CurrentAmbientTemperature - 78f < epsilon, "Failed: UPS.AddTemperatureReading/Current Temperature Getter");
            Debug.Assert(n.AverageAmbientTemperature - (89f + 95f + 87f + 78f) / 4f < epsilon, "FAILED: UPS.AverageTemperature/UPS.CalculateAverageTemperature/Getter");

            //Tests for the Model Class
            Debug.Assert(n2 == AtwaterMonitorModel.GetDeviceWithHostname("UPS_03"), "FAILED: Model.GetDevicesWithHostname()");
            Debug.Assert(n == AtwaterMonitorModel.GetDeviceWithIP("10.10.41.41"), "FAILED: Model.GetDeviceWithIP()");
            Debug.Assert(n2 == AtwaterMonitorModel.GetDevicesWithStatus(NetworkDevice.DeviceState.OffLine)[1] &&
                         n == AtwaterMonitorModel.GetDevicesWithStatus(NetworkDevice.DeviceState.OffLine)[0], "FAILED: Model.GetDevicesWithStatus()");
            Debug.Assert(n2 == AtwaterMonitorModel.GetDevicesAboveTemperature(79f)[0], "FAILED: Model.GetDevicesAboveTemperature()");
        }
Ejemplo n.º 2
0
        private bool UpdateUPS(UPS deviceToPoll)
        {
            //Console.WriteLine($"Updating Device at {deviceToPoll.IPAddress}");

            //No Temperature Probe Oid on this device. Skip for now.
            //TODO: Have this try to reaquire a temperature probe Oid?
            if (string.IsNullOrWhiteSpace(deviceToPoll.TemperatureSensorOid))
            {
                return(false);
            }

            try
            {
                //Version 1 Solution is just to grab the ambient temperature.
                //Niave Solution will assume UPS.TemperatureSensorOid is accurate.
                //TODO: Make this failover to the other Oids in case the Temperature Probe is moved to new port.
                KeyValuePair <string, string> temperatureResult = GetSnmpResultForOid(deviceToPoll.IPAddress, deviceToPoll.TemperatureSensorOid);
                deviceToPoll.State = UPS.DeviceState.OnLine;
                deviceToPoll.AddAmbientTemperatureReading(float.Parse(temperatureResult.Value), DateTime.Now);
            }
            catch (ImproperOidsException e)
            {
                Console.WriteLine("TemperatureProbeOid is incorrect or unit's IP has changed: {0}", e.Message);
                //TODO: Make this check for the other possible Temperature Probe Oids before failing out.
                return(false);
            }
            catch (SnmpException e)
            {
                Console.WriteLine("Cannot reach the Unit. Marking as offline. ({0})", e.Message);
                deviceToPoll.State = UPS.DeviceState.OffLine;
            }
            return(true);
        }