Script DCI

Started by MarcusH, May 11, 2022, 10:42:34 AM

Previous topic - Next topic

MarcusH

Hi,

Is there any way to in a script that runs as DCI identify which DCI that started the script?
I am trying to make one script for multiple DCI

MarcusH

Changed approach, one DCI that runs script and script then push return to different push DCI

Dawid Kellerman

Hi Marcus
if it is possible can share the final working script as an example unless you cant remove sensitive info as an example it would be much appreciated for example purposes.
Regards Dawid

Filipp Sudanov

Starting from 4.1.283 there is $dci variable that contains corresponding DCI object.

MarcusH

$dci works

Here exemple on what i have done.

CheckDownStatus(container objectid) loops all nodes in the container and gets latest value from DCI named Down, if any node has been down over 80 seconds it returns 80 else 0.

All below is run on same node named PushNode, this node is trusted on all nodes since i have trusted nodes active.

This version is run by a script DCI and pushes down value to a DCI with origin Push on PushNode

sub CheckDownStatus(obj)
{
  foreach(o : obj->children) {
  if(!o->isInMaintenanceMode)
  {
    downsince = GetDCIRawValue(o, FindDCIByName(o, "Down"));
    if(downsince > 80)
    {
    return 80;
    }
    }
  }
  return 0;
}

// AP Zone 1
PushDCIData($node, 3115, CheckDownStatus(FindObject("9347", $node)));
// AP Zone 2
PushDCIData($node, 3117, CheckDownStatus(FindObject("12216", $node)));


This version returns value to the same DCI that runs it, and as stated above only works from version 4.1.283

sub CheckDownStatus(obj)
{
  foreach(o : obj->children) {
  if(!o->isInMaintenanceMode)
  {
    downsince = GetDCIRawValue(o, FindDCIByName(o, "Down"));
    if(downsince > 80)
    {
    return 80;
    }
    }
  }
  return 0;
}

test = $dci->id;

// AP Zone 1
if(test = "3115"){ return CheckDownStatus(FindObject("9347", $node));}
// AP Zone 2
if(test = "3117"){ return CheckDownStatus(FindObject("12216", $node));}


My reason for these is that now i have one DCI that i can monitor if any node goes down in that group. I also like having things in scripts gives me more freedom, in some cases we call action on agents like the agent that is on the PC that runs the grafana screens has an action for text2speech and that is speaking some alarms with values that needs immediate action.


Dawid Kellerman

Thank you for a helpful write up, Marcus
Regards Dawid