• 0
Tanvir

Custom query for dynamic group

Question

Hi

I want create dynamic groups based on server role like print servers, AD servers, file servers etc. Could you please help me to to find out how can i create a custom query for the groupings or custom query if a service is running.

Thank you

Tanvir

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @Tanvir,

Apologies for the delay in a response - take a look at some of the PropertySources we ship with the product - if they're not in your account you should be able to pull them down from the repository. Here's an example of the underlying code for the Domain Controllers PropertySource, which looks for the "NTDS" service to be running, and then adds a category to the device (which you can then use to group the devices together.) So you could clone this, change the service it looks for, and change the category it assigns...

import com.santaba.agent.groovyapi.win32.WMI
import com.santaba.agent.groovyapi.win32.WMISession

// Set hostname
def hostname = hostProps.get('system.hostname');

// Form the full query.
def wmiQuery = "Select name,state from Win32_Service Where Name = 'NTDS'";

try
{
    // using default namespace
    def session = WMI.open(hostname); 
    def result = session.queryFirst("CIMv2", wmiQuery, 10); 

    // Did we get anything?
    if (result.STATE == "Running")
    {
        // Yes, apply the properties
        println 'system.categories=MicrosoftDomainController'
    }
}

catch(Exception e)
{
    println e
    return 1;
}

// Exit by returning 0.
return 0;

Best,

Kerry

Edited by Kerry DeVilbiss
linkage + updates

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.