Hello Dojo,
Is it possible to create custom properties through automation without having an alarm beforehand?
If so, how can this be done?
Also, is it possible to expose those properties on the Alarm Console through automation?
Thank you!
Hi ana,
Can you try this:
var propertyConfig = new PropertyConfig
{
Name = property.Name,
Type = "Alarm",
};PropertyManager.RegisterPropertyConfig(propertyConfig);
public class PropertyManager
{
private static ConcurrentDictionary<string, PropertyConfig> registredProperties = new ConcurrentDictionary<string, PropertyConfig>();/// <summary>
/// Registers a property in DataMiner system.
/// </summary>
/// <param name="property">Property to be registered.</param>
/// <returns>True if the property was registered;otherwise false.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="property"/> is null.</exception>
public static bool RegisterPropertyConfig(PropertyConfig property)
{
if (property == null)
{
throw new ArgumentNullException(nameof(property));
}if (registredProperties.ContainsKey($"{property.Name}.{property.Type}"))
{
return true;
}var properties = GetRegisteredProperties().ToArray();
if (properties.Any(p => p.Name == property.Name && string.Equals(p.Type, property.Type, StringComparison.InvariantCultureIgnoreCase)))
{
return true;
}var nextId = properties.Select(x => x.ID).Max() + 1;
property.ID = nextId;
try
{
var response = Engine.SLNet.SendSingleResponseMessage(new AddPropertyConfigMessage(property)) as UpdatePropertyConfigResponse;return response?.ID == nextId;
}
catch (Exception)
{
return false;
}
}/// <summary>
/// Gets an <see cref="IEnumerable{T}"/> of <see cref="PropertyConfig"/> with all registered properties.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="PropertyConfig"/> with all registered properties.</returns>
public static IEnumerable<PropertyConfig> GetRegisteredProperties()
{
try
{
var response = Engine.SLNet.SendSingleResponseMessage(new GetInfoMessage(InfoType.PropertyConfiguration)) as GetPropertyConfigurationResponse;var properties = response?.Properties ?? Enumerable.Empty<PropertyConfig>();
foreach (var prop in properties)
{
registredProperties.TryAdd($"{prop.Name}.{prop.Type.ToUpperInvariant()}", prop);
}return properties;
}
catch (Exception)
{
return Enumerable.Empty<PropertyConfig>();
}
}
}
Kind regards,
By the way, if the goal is to have the property visible in the Alarm Console, you will need to enable the IsFilterEnabled option when creating it:
var propertyConfig = new PropertyConfig
{
Name = property.Name,
Type = "Alarm",
IsFilterEnabled = true
};
Kind regards,