Forum Discussion

mnagel's avatar
mnagel
Icon for Professor rankProfessor
8 years ago

use ILPs for "applies to"?

I would like to be able to apply a DS only to servers that have been found running a service (DHCP Server, for example).  I can extract ILPs for this in the DS that finds the service running, but it does not appear there is any method to check for those in the Applies To logic.  I would consider using a PropertySource, but those are Groovy only, so not clear how that could work for this type of property.  I am not quite sure what this looks like, but ultimately I should be able to limit a DS based on what a device is doing dynamically without having to rescan it for each DS separately.  I can work around this by manually defining a property, but that is just one more place to introduce an error.  Or, perhaps I can work around this by defining a property via an API script.  It would be a lot easier to have something like this available in the Applies To toolset: getInstanceProperty(hostname,datasource,instance,"displayname") == "DHCP Server"

Thanks,

Mark

 

3 Replies

Replies have been turned off for this discussion
  • Hi Mark - 

    I think the PropertySource is the best route here, but it's possible I don't understand the problem.

    Is there a reason why Groovy couldn't determine whether a DHCP server running on a particular system? I can think of a number of ways (of varying degrees of elegance) to achieve this, depending its OS.

  • Can Groovy do WMI now?  Please direct me to the documentation on that.  

    I am able to populate an ILP on this -- already done in testing.  What I am looking for is a way to then actually use this data.  Right now, it looks like the only place you can reference an ILP is with the instanceProps.get("auto.PropertyName") mechanism in complex groovy datapoints and in filters where ILPs are extracted.  If that could be converted into a device property, I would love to see how as that would definitely solve the problem.  My idea was to create a way to search for them, but other methods that end the same way are fine by me!

    Thanks,

    Mark

     

     

  • Hey Mark,

    Here's an example of a Groovy script that queries WMI for a running service and adds a category to the device that can be used for AppliesTo. This one looks for the NTDS service (an Active Directory domain controller) and assigns category 'ADDS' to the device.  The example AppliesTo for the below code would be 'hasCategory("ADDS")'. Credit due to Michael Rodrigues on our datasource team for the script (which I've re-used with different service and category names.) This is the exact code from an "Active Directory Domain Controller" PropertySource: 

    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=ADDS'
        }
    }
    catch(Exception e)
    {
        println e
        return 1;
    }
    
    // Exit by returning 0.
    return 0;

    Cheers,

    Kerry