Script / Template for windows services

Started by theyareseven, November 28, 2017, 11:19:25 AM

Previous topic - Next topic

theyareseven

I have been trying to make a way so that NETXMS will auto find all services (auto ect) and monitor them, the system supports this for disk space ect but can't seem to map this to services. any ideas or help?

ty

twenrich

I use a script for instance discovery and a filter script to remove unwanted services.
Additional, custom attributes allow to include and exclude services per node.

Please see the attached image for usage in the template DCI.

Kind regards,
Thomas


Script windows_auto_services:

col_startup = 4;
array a;

table = AgentReadTable($node, "System.Services");
if (table == null)
{
    println "ERROR: Cannot read table from agent";
    return;
}

index = 0;
for (i=0; i<table->rowCount; i++)
    {
    startup = table->get(i, col_startup);
    if (startup == "Auto")
        {
        a[index++] = table->get(i, 0);
        println table->get(i, 0);
        }
    }

// trace(1, "discover_auto_services: return 0");

return a;


Script filter_windows_services:

sub filter_windows_service(svc)
{
attr = GetCustomAttribute($node, "SERVICE_EXCLUDE");
if (attr != null && inList(attr, ",", svc))
{
trace(1, $node->name . ": Service " . svc . " excluded by attribute SERVICE_EXCLUDE");
return false;
}
attr = GetCustomAttribute($node, "SERVICE_INCLUDE");
if (attr != null && inList(attr, ",", svc))
return true;

return
   (svc != "TBS")
&& (svc != "KtmRm")
&& (svc != "iphlpsvc")
&& (svc != "sppsvc")
&& (svc != "ShellHWDetection")
&& (svc != "ccmsetup")
&& (svc != "SysmonLog")
&& (!(svc ~= "^clr_optimization_.*") )
&& svc != "spupdsvc"
&& svc != "RDSessMgr"
&& svc != "DPS"
&& svc != "FontCache"
&& svc != "MSDTC"
&& svc != "WinRM"
&& svc != "gupdate"
&& svc != "wscsvc"
&& svc != "VSS"
&& svc != "wuauserv"
&& svc != "TrustedInstaller"
&& svc != "BackupExecAgentAccelerator"
&& svc != "CcmExec"
;
}

theyareseven

HI twenrich,

Thank you!!!! :) this is a great script, should be standard in the package!!!!

The only thing I have noticed is that for some reason, when I add in extra services to 'ignore' it still shows them AdobeUpdateService and alike but am sure that is something I have done / not doing.


ty