I have a use case where alarm ingestion into a connector follows this flow:
Correlation Rule triggers an automation script, which pushes data into a table in a connector.
I want to add a configuration parameter on the connector that enables or disables this entire flow. Ideally, I'd like to cut it off at the root by disabling the correlation rule itself when the parameter is toggled off.
I'm aware of workarounds, e.g. checking the parameter early in the automation script and exiting before doing any work. That's cheap and effective, but the correlation rule still fires and the script still starts for every alarm update, only to immediately exit.
Is there a way to programmatically enable or disable a correlation rule from a QAction (or automation script)? For example, via an SLNet message?
Hi Enis,
Yes, it's feasible to enable/disable a Correlation Rule from an Automation script.
We've already created a script for this before.
Here you can find the C# code for the Automation script:
namespace Update_Correlation_Rule_1
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Linq;
using Skyline.DataMiner.Automation;
using Skyline.DataMiner.Net.Correlation;
using Skyline.DataMiner.Net.Messages;/// <summary>
/// Represents a DataMiner Automation script.
/// </summary>
public class Script
{
/// <summary>
/// The script entry point.
/// </summary>
/// <param name="engine">Link with SLAutomation process.</param>
public void Run(IEngine engine)
{///Arguments to provide:
/// ** Correlationrule Name
/// ** true / false// get input string
// get input string
string correlationGroup = engine.GetScriptParam("selectCorrelationGroup").Value;
string correlationAction = engine.GetScriptParam("selectCorrelationAction").Value;// cast the selected action to a bool variable
bool correlationActionbool = false;
switch (correlationAction)
{
case "enable":
correlationActionbool = true;
break;
case "disable":
correlationActionbool = false;
break;
default:
break;
}// get list of correlation rules containing the selected Group name in the description
Dictionary<string, CorrelationRuleMeta> correlationRulesMeta = getMetas();
IEnumerable<KeyValuePair<string, CorrelationRuleMeta>> CorrelationskeyValuePairs = correlationRulesMeta.Where(x => x.Value.Description.Contains(correlationGroup));// check if the group is enabled
bool isEnabled = false;
//string[] corr_resp_array = new string[];foreach (var item in CorrelationskeyValuePairs)
{
if (correlationAction == "check")
isEnabled = item.Value.IsEnabled;
else
{
if (correlationActionbool)
{
if (!item.Value.IsEnabled)
{
if ( UpdateCorrelationRule(engine, item.Value.Name, correlationActionbool) == true)
{
isEnabled = true;
}
}
else
isEnabled = true;
}
else if (!correlationActionbool)
{
if (item.Value.IsEnabled)
{
if (UpdateCorrelationRule(engine, item.Value.Name, correlationActionbool) == true)
{
isEnabled = false;
}
else
isEnabled = true;
}
}
}
}
if (isEnabled)
{
engine.AddOrUpdateScriptOutput(UIVariables.VisualOverview.CreateKey("corrStatus"), "true");
}
else
{
engine.AddOrUpdateScriptOutput(UIVariables.VisualOverview.CreateKey("corrStatus"), "false");
}
}public bool UpdateCorrelationRule(IEngine engine, string name, bool enable)
{
Skyline.DataMiner.Net.Messages.GetCorrelationRuleMessage crRule = new GetCorrelationRuleMessage();
crRule.RuleName = name;UpdateCorrelationRuleMessage update = new UpdateCorrelationRuleMessage();
update.RuleDefinition = ((GetCorrelationRuleResponse)Engine.SLNet.SendSingleResponseMessage(crRule)).Definition;
update.RuleDefinition.IsEnabled = enable;
update.Type = UpdateCorrelationRuleMessage.UpdateType.Update;
DMSMessage[] UpdateResponse = Engine.SLNet.SendMessage(update);if (UpdateResponse.Length == 0)
{
engine.GenerateInformation(name + " not updated !");
return false;
}
else
{
return true;
}
}public Dictionary<string, CorrelationRuleMeta> getMetas()
{
Skyline.DataMiner.Net.Messages.GetAvailableCorrelationRulesMessage crmes = new Skyline.DataMiner.Net.Messages.GetAvailableCorrelationRulesMessage();
var response = Engine.SLNet.SendMessage(crmes);
AvailableCorrelationRulesResponse res = (AvailableCorrelationRulesResponse)response[0];
Dictionary<string, CorrelationRuleMeta> dMetas = new Dictionary<string, CorrelationRuleMeta>();
foreach (CorrelationRuleMeta crMeta in res.Rules)
{
dMetas.Add(crMeta.Name, crMeta);
}
return dMetas;
}
}
}
Please also add two parameters for the Automation Script which will be used as input for knowing the Correlation rule and action needed. :
- selectCorrelationGroup
- selectCorrelationAction : {enable, disable}
Kind regards,
It works as expected, thank you very much!