private void ParseResponse(string response) { var nameRegex = "(.+?name=\")(.+?_*)(\".+)"; var inputs = ObjectSettings.GetFilteredInputs(response, nameRegex).Where(n => n.Name != "tmpid" && n.Name != "id" && n.Name != "sensortype" && n.Name != "parenttags_").ToList(); var lists = ObjectSettings.GetDropDownList(response, nameRegex); var text = ObjectSettings.GetTextAreaFields(response, nameRegex); Targets = GenericSensorTarget.GetAllTargets(response).ToDictionary(t => t.Key, t => t.Value.ToArray()); foreach (var input in inputs) { AddCustom(input.Name, CleanValue(input.Value)); } foreach (var list in lists) { AddCustom(list.Name, CleanValue(list.Options.FirstOrDefault(o => o.Selected)?.Value)); //todo: does this crash if its null? } foreach (var t in text) { Add(t.Key, CleanValue(t.Value)); } }
/// <summary> /// Asynchronously rtrieves all sensor targets of a sensor type not currently supported by PrtgAPI. /// </summary> /// <param name="deviceId">The ID of the device to retrieve sensor targets for.</param> /// <param name="sensorType">The type of sensor to retrieve sensor targets for.</param> /// <param name="tableName">The name of the Dropdown List or Checkbox Group the sensor targets belong to. If this value is null, PrtgAPI will attempt to guess the name of the table. If this value cannot be guessed or is not valid, an <see cref="ArgumentException"/> will be thrown listing all possible values.</param> /// <param name="progressCallback">A callback function used to monitor the progress of the request. If this function returns false, the request is aborted and this method returns null.</param> /// <returns>If the request is allowed to run to completion, a generic list of sensor targets. If the request is aborted from the progress callback, this method returns null.</returns> public async Task <List <GenericSensorTarget> > GetSensorTargetsAsync(int deviceId, string sensorType, string tableName = null, Func <int, bool> progressCallback = null) => await client.ResolveSensorTargetsAsync(deviceId, sensorType, progressCallback, r => GenericSensorTarget.GetTargets(r, tableName)).ConfigureAwait(false);
/// <summary> /// Retrieves all sensor targets of a sensor type not currently supported by PrtgAPI. /// </summary> /// <param name="deviceId">The ID of the device to retrieve sensor targets for.</param> /// <param name="sensorType">The type of sensor to retrieve sensor targets for.</param> /// <param name="tableName">The name of the Dropdown List or Checkbox Group the sensor targets belong to. If this value is null, PrtgAPI will attempt to guess the name of the table. If this value cannot be guessed or is not valid, an <see cref="ArgumentException"/> will be thrown listing all possible values.</param> /// <param name="progressCallback">A callback function used to monitor the progress of the request. If this function returns false, the request is aborted and this method returns null.</param> /// <returns>If the request is allowed to run to completion, a generic list of sensor targets. If the request is aborted from the progress callback, this method returns null.</returns> public List <GenericSensorTarget> GetSensorTargets(int deviceId, string sensorType, string tableName = null, Func <int, bool> progressCallback = null) => client.ResolveSensorTargets(deviceId, sensorType, progressCallback, r => GenericSensorTarget.GetTargets(r, tableName));
/// <summary> /// Asynchronously rtrieves all sensor targets of a sensor type not currently supported by PrtgAPI. /// </summary> /// <param name="deviceOrId">The device or ID of the device to retrieve sensor targets for.</param> /// <param name="sensorType">The type of sensor to retrieve sensor targets for.</param> /// <param name="tableName">The name of the Dropdown List or Checkbox Group the sensor targets belong to. If this value is null, PrtgAPI will attempt to guess the name of the table. If this value cannot be guessed or is not valid, an <see cref="ArgumentException"/> will be thrown listing all possible values.</param> /// <param name="progressCallback">A callback function used to monitor the progress of the request. If this function returns false, the request is aborted and this method returns null.</param> /// <param name="timeout">Duration (in seconds) to wait for sensor targets to resolve.</param> /// <param name="queryParameters">A <see cref="SensorQueryTarget"/>, <see cref="SensorQueryTargetParameters"/> or <see cref="SensorMultiQueryTargetParameters"/> value specifying the parameters must be known prior to interrogating a sensor's dynamic parameters (such as the SNMP Library file to use or IPMI UserName and Password).</param> /// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <exception cref="TimeoutException">Sensor targets failed to resolve within the specified timespan.</exception> /// <returns>If the request is allowed to run to completion, a generic list of sensor targets. If the request is aborted from the progress callback, this method returns null.</returns> public async Task <List <GenericSensorTarget> > GetSensorTargetsAsync(Either <Device, int> deviceOrId, string sensorType, string tableName = null, Func <int, bool> progressCallback = null, int timeout = 60, ISensorQueryTargetParameters queryParameters = null, CancellationToken token = default(CancellationToken)) => await client.ResolveSensorTargetsAsync(deviceOrId, sensorType, progressCallback, timeout, queryParameters, token, r => GenericSensorTarget.GetTargets(r, tableName)).ConfigureAwait(false);
/// <summary> /// Retrieves all sensor targets of a sensor type not currently supported by PrtgAPI. /// </summary> /// <param name="deviceId">The ID of the device to retrieve sensor targets for.</param> /// <param name="sensorType">The type of sensor to retrieve sensor targets for.</param> /// <param name="tableName">The name of the Dropdown List or Checkbox Group the sensor targets belong to. If this value is null, PrtgAPI will attempt to guess the name of the table. If this value cannot be guessed or is not valid, an <see cref="ArgumentException"/> will be thrown listing all possible values.</param> /// <param name="progressCallback">A callback function used to monitor the progress of the request. If this function returns false, the request is aborted and this method returns null.</param> /// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>If the request is allowed to run to completion, a generic list of sensor targets. If the request is aborted from the progress callback, this method returns null.</returns> public List <GenericSensorTarget> GetSensorTargets(int deviceId, string sensorType, string tableName = null, Func <int, bool> progressCallback = null, CancellationToken token = default(CancellationToken)) => client.ResolveSensorTargets(deviceId, sensorType, progressCallback, token, r => GenericSensorTarget.GetTargets(r, tableName));
/// <summary> /// Asynchronously rtrieves all sensor targets of a sensor type not currently supported by PrtgAPI. /// </summary> /// <param name="deviceId">The ID of the device to retrieve sensor targets for.</param> /// <param name="sensorType">The type of sensor to retrieve sensor targets for.</param> /// <param name="tableName">The name of the Dropdown List or Checkbox Group the sensor targets belong to. If this value is null, PrtgAPI will attempt to guess the name of the table. If this value cannot be guessed or is not valid, an <see cref="ArgumentException"/> will be thrown listing all possible values.</param> /// <param name="progressCallback">A callback function used to monitor the progress of the request. If this function returns false, the request is aborted and this method returns null.</param> /// <param name="token">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <param name="timeout">Duration (in seconds) to wait for sensor targets to resolve.</param> /// <exception cref="TimeoutException">Sensor targets failed to resolve within the specified timespan.</exception> /// <returns>If the request is allowed to run to completion, a generic list of sensor targets. If the request is aborted from the progress callback, this method returns null.</returns> public async Task <List <GenericSensorTarget> > GetSensorTargetsAsync(int deviceId, string sensorType, string tableName = null, Func <int, bool> progressCallback = null, int timeout = 60, CancellationToken token = default(CancellationToken)) => await client.ResolveSensorTargetsAsync(deviceId, sensorType, progressCallback, timeout, token, r => GenericSensorTarget.GetTargets(r, tableName)).ConfigureAwait(false);