Filter Array

Is there any way to filter an array in a function? I am looking to get a count of the number of instances of a running executable on a server. So basically make an SNMP call to get a list of running processes. Filter the list by the name of a single process, then get a count using array_count.

Or alternatively loop through an array and get a count using variables and an if statement.

Todd

Give this a try…

[array_element(oid_column(“1.3.6.1.2.1.25.4.2.1.2”), array_find(oid_column(“1.3.6.1.2.1.25.4.2.1.2”),“svchost.exe”))]
[concatenate ( "Instances: ", array_find(oid_column(“1.3.6.1.2.1.25.4.2.1.2”),“svchost.exe”))]

This worked great for me, thank you very much.

Anyone have any idea how to do something similar to this in probe form?

I’ve taken a stab at it, having it graph the value of ‘array_find(oid_column(“1.3.6.1.2.1.25.4.2.1.2”),“_progres.exe”)’, but I keep getting numbers that don’t match up. For example: Dude reports 41 instances of _progres.exe, but task manager on the system only reports 15. I’ve been unable to account for this variance.

IT WORKS :slight_smile:

Function
name: findsvch
code: if(array_size(oid_column(“1.3.6.1.2.1.25.4.2.1.2”,10,29)), array_find(oid_column(“1.3.6.1.2.1.25.4.2.1.2”,10,29),“svchost.exe”),“False”)

Probe
name: svccount
type: function
available: findsvch()<>“False”
error: if(findsvch()<>“False”, if(findsvch(),“”, “No Svchost.exe running”), “Cant read device”)
value: findsvch()
unit: total

Hello!
This function works for the whole word in the value only. We need to find the strings which contain some word (but the whole string is longer) and count the quontity of such strings. Can we use any wildcards or maybe you know another functions which can do it?

Hi,
this is a historical post, but the return value of the findsvch() function is not the count of running instances? I think it will return the index of the first value “svchost.exe” found in the array oid_column(“1.3.6.1.2.1.25.4.2.1.2”).
Or am I wrong?

Yes. Its return the first index found in array.
I’m also trying to get, for example, count of repetition in an array.