Author Topic: Understanding the AgentReadList vs readAgentList  (Read 298 times)

Borgso

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Understanding the AgentReadList vs readAgentList
« on: October 11, 2019, 09:22:30 pm »
Have been using AgentReadList in different scenarios to dynamic apply template and dci instances
Could need some help to get it rewritten for NXLSv3


What worked in 2.2.x

Scenario 1:

DCI on agentless node, using a "source node" and "Instance discovery method: Script", called with
Quote
DW::DiscoverActiveMQ("DLQDetailsQueue")

DW::DiscoverActiveMQ script is:
Code: [Select]
if ($1 == "ActiveMQ") {
  //return AgentReadList($node, "DiscoverActiveMQ(" . $targetObject->ipAddr . ")");
  return $targetObject->readAgentList("DiscoverActiveMQ(" . $targetObject->ipAddr . ")");
}

ExternalList DiscoverActiveMQ do a do a call from source node to node and get a instance list to create DCI to poll info using a ExternalParameter (script on source node -> node) on each instance.




Scenario 2:
AutoApply template if user X is within /etc/passwd.

Using a script library with following code and "ExternalList = UserList:cut -d: -f1 /etc/passwd"
Code: [Select]
sub ServiceCheck(ServiceName) {
  if ($node->isAgent && $node->platformName like "Linux-*") {
    users = AgentReadList($node,"UserList");
    if ( users == null ) return null;
    foreach ( user : users ) {
      if ( user == ServiceName ) return true;
    }
  }
  return false;
}

Victor Kirhenshtein

  • Lead Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6883
    • View Profile
Re: Understanding the AgentReadList vs readAgentList
« Reply #1 on: October 14, 2019, 01:33:58 pm »
Hi,

readAgentList is a node object method, so if you were calling

AgentReadList($node, ...

(read agent parameter from node pointed by $node variable) you now should use

$node->readAgentList(...

to read list from agent on same node.

Best regards,
Victor

Borgso

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Understanding the AgentReadList vs readAgentList
« Reply #2 on: October 14, 2019, 08:52:36 pm »
Hi and thank for reply.

I tried what you suggest, but it doesnt work as before:

ServiceName is username within /etc/passwd catched using ExternalList on the node.

Does not work:
Code: [Select]
if ($node->isAgent && $node->platformName like "Linux-*") {
    users = $node->readAgentList("UserList");
    if ( users == null ) return null;
    foreach ( user : users ) {
      if ( user == ServiceName ) return true;
    }
  }
  return false;

Does work, but is not the correct way..
Code: [Select]
if ($node->isAgent && $node->platformName like "Linux-*") {
    users = AgentReadList($node,"UserList");
    if ( users == null ) return null;
    foreach ( user : users ) {
      if ( user == ServiceName ) return true;
    }
  }
  return false;


However, if i add node to template first and then do "Configuration Poll" with $node->readAgentList version, it does not remove the node from template even if "Remove this template automatically when node no longer passes through filter"
It does get removed/unbind if i only put "return false;" in the Automatic Apply Rules.