externalparameterprovider clarification

Started by it_user1, October 06, 2017, 10:20:32 AM

Previous topic - Next topic

it_user1

Hi, i done some research on forum to understand how to retrieve a table from powershell's script and create a dci.

I found that dci's table doesn't support powershell and i can user "externalparameterprovider" on agent's file conf. But how?

In my case i need to retrieve a list of virtual machine from hyper-v cluster with powershell command Get-vm. My question is how can translate columns output from powershell script and traslate on table columns on dci's table?

thank you

Andrea


Tursiops

Hi,

I recall seeing that support for External Tables was added in a release candidate for 2.1:
https://www.netxms.org/documentation/adminguide/agent-management.html?highlight=externaltable
You could use this to call a PowerShell script, which returns the values in the required format.
Someone else who may have already used this functionality may be able to assist further (I haven't used it).


Otherwise, I am assuming you are referring to this post: https://www.netxms.org/forum/configuration/executing-powershell-with-tabel-result/
ExternalParametersProvider will not give you an actual table DCI.
But you can use it to return a number of name=value pairs, where "name" will be the parameter of your DCI and "value" the value for it.
Together with an ExternalList (e.g. by taking the output of (get-Vm).Name) you could then use Instance Discovery to create DCIs for each VM and any data point you may be looking for.

That actually does not rely on using ExternalParametersProvider (you could just have a number of individual ExternalParameters that take the VM Name as parameter), but it would make sense to do so. Better to call a single PowerShell every so often by the agent to pull all data you want, than to start a new PowerShell process for each individual DCI for each individual VM.

The ExternalParametersProvider documentation is right above the ExternalTable one given in the link above. Just scroll up a few lines.


Cheers

it_user1

i have read about externaltable command, but with powershell i don't know what to use as column separator.

I have thought also to use a csv file generate from powershell and copied on netxms server, but i don't found anything about it on user manual and on forum

regards

Andrea

Tursiops

Hi,

A very simple example I just tested using ExternalTable and PowerShell.

Add this to your Agent configuration:
ExternalTable=TableTest:instanceColumns=Index;description=Table with data;separator=|:powershell -c "\"Index|Column 01|Column 02`nIndex 01|Data 01|Data 11`nIndex 02|Data 02|Data 12\""

What this does is:

  • create an External Table called "TableTest".
  • the Instance Column is called "Index" (the column "Index" exists in the data)
  • the Description is just that, the description you see when you select this table as DCI
  • the separator is set to |, so the data you provide needs to have its columns separated by |. You could make this something else.
  • provide the actual command that generates the data. In this came a simple PowerShell command to print some text
Nothing is stopping you from calling an PowerShell script to return the data.
You can also pass parameters. Just used ExternalTable(*) instead of ExternalTable and then reference the parameters as usual using $1, $2, etc.
Keep in mind if you need to use actual $ in your command (e.g. $_), you need to escape the $ by writing $$ (e.g. $$_).

See attached image for a screenshot of how this table looks like once it has been pulled into NetXMS.

Cheers

it_user1

#4
thank you for reply, i have created the script and now works fine

i share my code if anyone is interested

ExternalTable=VMList:instanceColumns=Index;description=Tabella lista VM;separator=|:powershell C:\NetXMS\script\vm.ps1

and this is my script

$s = "Index|Name|State|Status";
$i = 1;
$vm = Get-VM;
ForEach($item in $vm)
{
  $s = $s + "`n" + $i + "|" + $($item.Name) + "|" + $($item.State) + "|" + $($item.Status) ;
  $i = $i +1;
}
echo $s;


regards

Andrea