public void SystemInfo_EscapesQuotes_Numbers()
        {
            var item   = SystemInfoItem.ProcessItem("\"2002\"");
            var result = GetSystemInfoResponse <DeviceProcessInfo>(item);

            Assert.AreEqual(2002, result.ProcessId);
        }
Example #2
0
        private void AssertAllSystemInfoPropertiesDontHaveValues <T>(SystemInfoItem item, Func <PropertyInfo, bool> customHandler = null) where T : IDeviceInfo
        {
            var client = GetSystemInfoClient(item);

            Func <PropertyInfo, bool> innerCustomHandler = p =>
            {
                if (p.Name == "DeviceId")
                {
                    return(true);
                }

                if (p.Name == "Type")
                {
                    return(true);
                }

                if (customHandler != null)
                {
                    return(customHandler(p));
                }

                return(false);
            };

            var obj = client.GetSystemInfo <T>(1001).Single();

            AssertEx.AllPropertiesAreDefault(obj, innerCustomHandler);
        }
        public void SystemInfo_EscapesQuotes_FirstObject_MiddleProperty()
        {
            var normal = SystemInfoItem.UserItem();
            var test   = SystemInfoItem.UserItem("\"first\"", "second", displayName: "\"third\"");

            ValidateEscapeQuotes(1, 0, test, normal);
        }
        public void SystemInfo_Hardware_PropertiesMapCorrectly()
        {
            var name         = "\"Name\"";
            var description  = "\"Description\"";
            var @class       = "\"Class\"";
            var caption      = "\"Caption\"";
            var state        = "\"<img src=\\\"/images/state_.png\\\"> State\"";
            var serialNumber = "\"SerialNumber\"";
            var capacity     = "1234567890123456789";
            var receiveTime  = "01-02-2003 21:10:13.425";
            var displayName  = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceHardwareInfo>(
                SystemInfoItem.HardwareItem(name, description, @class, caption,
                                            state, serialNumber, capacity, receiveTime, displayName
                                            )
                );

            AssertAreEqual(name, obj.Name);
            AssertAreEqual(description, obj.Description);
            AssertAreEqual(@class, obj.Class);
            AssertAreEqual(caption, obj.Caption);
            AssertAreEqual("State", obj.State);
            AssertAreEqual(serialNumber, obj.SerialNumber);
            AssertAreEqual(Convert.ToInt64(capacity), obj.Capacity);
            AssertAreEqual(DateTime.ParseExact(receiveTime, "dd-MM-yyyy HH:mm:ss.FFF", CultureInfo.InvariantCulture), obj.LastUpdated);
            AssertAreEqual(displayName, obj.DisplayName);
        }
Example #5
0
        public void SystemInfo_Hardware_PropertiesMapCorrectly()
        {
            var name         = "\"Name\"";
            var description  = "\"Description\"";
            var @class       = "\"Class\"";
            var caption      = "\"Caption\"";
            var state        = "\"<img src=\\\"/images/state_.png\\\"> State\"";
            var serialNumber = "\"SerialNumber\"";
            var capacity     = "1234567890123456789";
            var displayName  = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceHardwareInfo>(
                SystemInfoItem.HardwareItem(name, description, @class, caption,
                                            state, serialNumber, capacity, displayName
                                            )
                );

            AssertAreEqual(name, obj.Name);
            AssertAreEqual(description, obj.Description);
            AssertAreEqual(@class, obj.Class);
            AssertAreEqual(caption, obj.Caption);
            AssertAreEqual("State", obj.State);
            AssertAreEqual(serialNumber, obj.SerialNumber);
            AssertAreEqual(Convert.ToInt64(capacity), obj.Capacity);
            AssertAreEqual(displayName, obj.DisplayName);
        }
        public void SystemInfo_EscapesQuotes_LastObject_LastProperty()
        {
            var normal = SystemInfoItem.UserItem();
            var test   = SystemInfoItem.UserItem("\"first\"", "\"second\"", displayName: "third");

            ValidateEscapeQuotes(0, 1, normal, test);
        }
Example #7
0
        private T GetSystemInfoResponse <T>(SystemInfoItem item) where T : IDeviceInfo
        {
            var client = GetSystemInfoClient(item);

            var obj = client.GetSystemInfo <T>(1001);

            return(obj.Single());
        }
Example #8
0
        private void AssertAllSystemInfoPropertiesHaveValues <T>(SystemInfoItem item, Func <PropertyInfo, bool> customHandler = null) where T : IDeviceInfo
        {
            var client = GetSystemInfoClient(item);

            var obj = client.GetSystemInfo <T>(1001).Single();

            AssertEx.AllPropertiesAreNotDefault(obj, customHandler);
        }
Example #9
0
 public void SystemInfo_AllPropertiesAreNull()
 {
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceSystemInfo>(SystemInfoItem.SystemItem(null, null, null, null, null));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceHardwareInfo>(SystemInfoItem.HardwareItem(null, null, null, null, null, null, null, null));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceSoftwareInfo>(SystemInfoItem.SoftwareItem(null, null, null, null, null, null));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceProcessInfo>(SystemInfoItem.ProcessItem(null, null, null, null));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceServiceInfo>(SystemInfoItem.ServiceItem(null, null, null, null, null, null));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceUserInfo>(SystemInfoItem.UserItem(null, null, null));
 }
Example #10
0
 public void SystemInfo_AllPropertiesAreEmpty()
 {
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceSystemInfo>(SystemInfoItem.SystemItem("\"\"", "\"\"", "\"\"", "\"\"", "\"\""));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceHardwareInfo>(SystemInfoItem.HardwareItem("\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\""));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceSoftwareInfo>(SystemInfoItem.SoftwareItem("\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\""));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceProcessInfo>(SystemInfoItem.ProcessItem("\"0\"", "\"\"", "\"\"", "\"\""));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceServiceInfo>(SystemInfoItem.ServiceItem("\"\"", "\"\"", "\"\"", "\"\"", "\"\"", "\"\""));
     AssertAllSystemInfoPropertiesDontHaveValues <DeviceUserInfo>(SystemInfoItem.UserItem("\"\"", "\"\"", "\"\""));
 }
Example #11
0
 public void SystemInfo_NoPropertiesAreStrings()
 {
     GetSystemInfoResponse <DeviceSystemInfo>(SystemInfoItem.SystemItem("1", "2", "3", "4", "5"));
     GetSystemInfoResponse <DeviceHardwareInfo>(SystemInfoItem.HardwareItem("1", "2", "3", "4", "5", "6", "7", "8"));
     GetSystemInfoResponse <DeviceSoftwareInfo>(SystemInfoItem.SoftwareItem("1", "2", "3", "\"2017-05-23-00-00-00\"", "5", "6"));
     GetSystemInfoResponse <DeviceProcessInfo>(SystemInfoItem.ProcessItem("1", "2", "\"2018-08-31 19:36:26\"", "4"));
     GetSystemInfoResponse <DeviceServiceInfo>(SystemInfoItem.ServiceItem("1", "2", "3", "4", "5"));
     GetSystemInfoResponse <DeviceUserInfo>(SystemInfoItem.UserItem("1", "2", "3"));
 }
Example #12
0
 private PrtgClient GetFullSummaryClient()
 {
     return(GetSystemInfoClient(
                SystemInfoItem.SystemItem(), SystemInfoItem.SystemItem(),
                SystemInfoItem.HardwareItem(), SystemInfoItem.HardwareItem(),
                SystemInfoItem.SoftwareItem(), SystemInfoItem.SoftwareItem(),
                SystemInfoItem.ProcessItem(), SystemInfoItem.ProcessItem(),
                SystemInfoItem.ServiceItem(), SystemInfoItem.ServiceItem(),
                SystemInfoItem.UserItem(), SystemInfoItem.UserItem()
                ));
 }
Example #13
0
        public void SystemInfo_User_PropertiesMapCorrectly()
        {
            var domain      = "\"Domain\"";
            var user        = "******"User\"";
            var displayName = "\"Domain\\\\User\"";

            var obj = GetSystemInfoResponse <DeviceUserInfo>(
                SystemInfoItem.UserItem(domain, user, displayName)
                );

            AssertAreEqual(domain, obj.Domain);
            AssertAreEqual(user, obj.User);
            AssertAreEqual("Domain\\User", obj.DisplayName);
        }
Example #14
0
        public void SystemInfo_Process_PropertiesMapCorrectly()
        {
            var processId    = "3";
            var caption      = "\"Caption\"";
            var creationDate = "\"2018-08-31 19:36:26\"";
            var displayName  = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceProcessInfo>(
                SystemInfoItem.ProcessItem(processId, caption, creationDate, displayName)
                );

            AssertAreEqual(Convert.ToInt32(processId), obj.ProcessId);
            AssertAreEqual(caption, obj.Caption);
            AssertAreEqual(DateTime.ParseExact(creationDate.Trim('"'), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), obj.CreationDate);
            AssertAreEqual(displayName, obj.DisplayName);
        }
        public void SystemInfo_User_PropertiesMapCorrectly()
        {
            var domain      = "\"Domain\"";
            var user        = "******"User\"";
            var receiveTime = "01-02-2003 21:10:13.425";
            var displayName = "\"Domain\\\\User\"";

            var obj = GetSystemInfoResponse <DeviceUserInfo>(
                SystemInfoItem.UserItem(domain, user, receiveTime, displayName)
                );

            AssertAreEqual(domain, obj.Domain);
            AssertAreEqual(user, obj.User);
            AssertAreEqual(DateTime.ParseExact(receiveTime, "dd-MM-yyyy HH:mm:ss.FFF", CultureInfo.InvariantCulture), obj.LastUpdated);
            AssertAreEqual("Domain\\User", obj.DisplayName);
        }
Example #16
0
        public void SystemInfo_System_PropertiesMapCorrectly()
        {
            var key         = "\"Key / Adapter\"";
            var value       = "\"Value\"";
            var id          = "3";
            var adapter     = "\"Adapter\"";
            var displayName = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceSystemInfo>(
                SystemInfoItem.SystemItem(key, value, id, adapter, displayName)
                );

            AssertAreEqual("Key", obj.Property);
            AssertAreEqual(value, obj.Value);
            AssertAreEqual(Convert.ToInt32(id), obj.Id);
            AssertAreEqual(adapter, obj.Adapter);
            AssertAreEqual(displayName, obj.DisplayName);
        }
Example #17
0
        public void SystemInfo_AllPropertiesHaveValues()
        {
            AssertAllSystemInfoPropertiesHaveValues <DeviceSystemInfo>(SystemInfoItem.SystemItem(), p =>
            {
                if (p.Name == "Type")
                {
                    return(true);
                }

                return(false);
            });

            AssertAllSystemInfoPropertiesHaveValues <DeviceHardwareInfo>(SystemInfoItem.HardwareItem(serialNumber: "1234", capacity: "100"));
            AssertAllSystemInfoPropertiesHaveValues <DeviceSoftwareInfo>(SystemInfoItem.SoftwareItem());
            AssertAllSystemInfoPropertiesHaveValues <DeviceProcessInfo>(SystemInfoItem.ProcessItem());
            AssertAllSystemInfoPropertiesHaveValues <DeviceServiceInfo>(SystemInfoItem.ServiceItem());
            AssertAllSystemInfoPropertiesHaveValues <DeviceUserInfo>(SystemInfoItem.UserItem());
        }
        public void SystemInfo_System_PropertiesMapCorrectly()
        {
            var key         = "\"Key / Adapter\"";
            var value       = "\"Value\"";
            var id          = "3";
            var adapter     = "\"Adapter\"";
            var receiveTime = "01-02-2003 21:10:13.425";
            var displayName = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceSystemInfo>(
                SystemInfoItem.SystemItem(key, value, id, adapter, receiveTime, displayName)
                );

            AssertAreEqual("Key", obj.Property);
            AssertAreEqual(value, obj.Value);
            AssertAreEqual(Convert.ToInt32(id), obj.Id);
            AssertAreEqual(adapter, obj.Adapter);
            AssertAreEqual(DateTime.ParseExact(receiveTime, "dd-MM-yyyy HH:mm:ss.FFF", CultureInfo.InvariantCulture), obj.LastUpdated);
            AssertAreEqual(displayName, obj.DisplayName);
        }
Example #19
0
        public void SystemInfo_Service_PropertiesMapCorrectly()
        {
            var name        = "\"Name\"";
            var description = "\"Description\"";
            var startName   = "\"StartName\"";
            var startMode   = "\"StartMode\"";
            var state       = "\"<img src=\\\"/images/state_stopped.png\\\"> State\"";
            var displayName = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceServiceInfo>(
                SystemInfoItem.ServiceItem(name, description, startName, startMode, state, displayName)
                );

            AssertAreEqual(name, obj.Name);
            AssertAreEqual(description, obj.Description);
            AssertAreEqual(startName, obj.User);
            AssertAreEqual(startMode, obj.StartMode);
            AssertAreEqual("State", obj.State);
            AssertAreEqual(displayName, obj.DisplayName);
        }
Example #20
0
        public void SystemInfo_Software_PropertiesMapCorrectly()
        {
            var name        = "\"Name\"";
            var vendor      = "\"Vendor\"";
            var version     = "1.2";
            var date        = "\"2017-05-23-00-00-00\"";
            var size        = "1234";
            var displayName = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceSoftwareInfo>(
                SystemInfoItem.SoftwareItem(name, vendor, version, date, size, displayName)
                );

            AssertAreEqual(name, obj.Name);
            AssertAreEqual(vendor, obj.Vendor);
            AssertAreEqual(Version.Parse(version), obj.Version);
            AssertAreEqual(ParameterHelpers.StringToDate(date.Trim('"')), obj.InstallDate);
            AssertAreEqual(Convert.ToInt32(size), obj.Size);
            AssertAreEqual(displayName, obj.DisplayName);
        }
        public void SystemInfo_Software_PropertiesMapCorrectly()
        {
            var name        = "\"Name\"";
            var vendor      = "\"Vendor\"";
            var version     = "1.2";
            var date        = "\"2017-05-23-00-00-00\"";
            var size        = "1234";
            var receiveTime = "01-02-2003 21:10:13.425";
            var displayName = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceSoftwareInfo>(
                SystemInfoItem.SoftwareItem(name, vendor, version, date, size, receiveTime, displayName)
                );

            AssertAreEqual(name, obj.Name);
            AssertAreEqual(vendor, obj.Vendor);
            AssertAreEqual(Version.Parse(version), obj.Version);
            AssertAreEqual(TypeHelpers.StringToDate(date.Trim('"')), obj.InstallDate);
            AssertAreEqual(Convert.ToInt32(size), obj.Size);
            AssertAreEqual(DateTime.ParseExact(receiveTime, "dd-MM-yyyy HH:mm:ss.FFF", CultureInfo.InvariantCulture), obj.LastUpdated);
            AssertAreEqual(displayName, obj.DisplayName);
        }
        public void SystemInfo_Service_PropertiesMapCorrectly()
        {
            var name        = "\"Name\"";
            var description = "\"Description\"";
            var startName   = "\"StartName\"";
            var startMode   = "\"StartMode\"";
            var state       = "\"<img src=\\\"/images/state_stopped.png\\\"> State\"";
            var receiveTime = "01-02-2003 21:10:13.425";
            var displayName = "\"DisplayName\"";

            var obj = GetSystemInfoResponse <DeviceServiceInfo>(
                SystemInfoItem.ServiceItem(name, description, startName, startMode, state, receiveTime, displayName)
                );

            AssertAreEqual(name, obj.Name);
            AssertAreEqual(description, obj.Description);
            AssertAreEqual(startName, obj.User);
            AssertAreEqual(startMode, obj.StartMode);
            AssertAreEqual("State", obj.State);
            AssertAreEqual(DateTime.ParseExact(receiveTime, "dd-MM-yyyy HH:mm:ss.FFF", CultureInfo.InvariantCulture), obj.LastUpdated);
            AssertAreEqual(displayName, obj.DisplayName);
        }
        private IWebResponse GetTableResponse(string address, string function, bool async)
        {
            var components = UrlUtilities.CrackUrl(address);

            Content?content;

            try
            {
                content = components["content"].DescriptionToEnum <Content>();
            }
            catch
            {
                content = null;
            }

            var count = GetCount(components, content);

            //Hack to make test "forces streaming with a date filter and returns no results" work
            if (content == Content.Logs && count == 0 && components["columns"] == "objid,name")
            {
                count   = 501;
                address = address.Replace("count=1", "count=501");
            }

            if (function == nameof(XmlFunction.HistoricData))
            {
                return(new SensorHistoryResponse(GetItems(i => new SensorHistoryItem(), count)));
            }

            var columns = components["columns"]?.Split(',');

            switch (content)
            {
            case Content.Sensors: return(Sensors(CreateSensor, count, columns, address, async));

            case Content.Devices: return(Devices(CreateDevice, count, columns, address, async));

            case Content.Groups:  return(Groups(CreateGroup, count, columns, address, async));

            case Content.Probes: return(Probes(CreateProbe, count, columns, address, async));

            case Content.Logs:
                if (IsGetTotalLogs(address))
                {
                    return(TotalLogsResponse());
                }

                return(Messages(i => new MessageItem($"WMI Remote Ping{i}"), count));

            case Content.History: return(new ModificationHistoryResponse(new ModificationHistoryItem()));

            case Content.Notifications: return(Notifications(CreateNotification, count));

            case Content.Schedules: return(Schedules(CreateSchedule, count));

            case Content.Channels: return(new ChannelResponse(GetItems(Content.Channels, i => new ChannelItem(), 1)));

            case Content.Objects:
                return(Objects(address, function, components));

            case Content.Triggers:
                return(new NotificationTriggerResponse(
                           NotificationTriggerItem.StateTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group"),
                           NotificationTriggerItem.ThresholdTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group", offNotificationAction: "300|Email to all members of group PRTG Users Group"),
                           NotificationTriggerItem.SpeedTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group", offNotificationAction: "300|Email to all members of group PRTG Users Group"),
                           NotificationTriggerItem.VolumeTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group"),
                           NotificationTriggerItem.ChangeTrigger(onNotificationAction: "300|Email to all members of group PRTG Users Group")
                           ));

            case Content.SysInfo:
                return(new SystemInfoResponse(
                           SystemInfoItem.SystemItem(), SystemInfoItem.HardwareItem(), SystemInfoItem.SoftwareItem(),
                           SystemInfoItem.ProcessItem(), SystemInfoItem.ServiceItem(), SystemInfoItem.UserItem()
                           ));

            default:
                throw new NotImplementedException($"Unknown content '{content}' requested from {nameof(MultiTypeResponse)}");
            }
        }
Example #24
0
        public void SystemInfo_Software_Version_MajorNumberOnly()
        {
            var obj = GetSystemInfoResponse <DeviceSoftwareInfo>(SystemInfoItem.SoftwareItem(version: "5"));

            Assert.AreEqual(obj.Version.ToString(), "5.0");
        }