Ejemplo n.º 1
0
    def collect(self, config):

        log.info('{0}:Start Collection of Services'.format(config.id))
        ds0 = config.datasources[0]

        scheme = ds0.zWinScheme
        port = int(ds0.zWinRMPort)
        auth_type = 'kerberos' if '@' in ds0.zWinRMUser else 'basic'
        connectiontype = 'Keep-Alive'
        keytab = ds0.zWinKeyTabFilePath
        dcip = ds0.zWinKDC

        servicename = ds0.params['servicename']

        WinRMQueries = [
            create_enum_info('select name, state, status, displayname'\
             ' from Win32_Service where name = "{0}"'.format(servicename))]

        conn_info = ConnectionInfo(ds0.manageIp, auth_type, ds0.zWinRMUser,
                                   ds0.zWinRMPassword, scheme, port,
                                   connectiontype, keytab, dcip)
        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
    def collect(self, config):

        ds0 = config.datasources[0]

        # build dictionary of datasource service info
        self.buildServicesDict(config.datasources)

        run_query = False
        for ds in config.datasources:
            id = ds.params['servicename']
            svc_data = self.services.get(id)
            if svc_data.get('manual') or len(svc_data.get('modes',[])) > 0:
                run_query = True
                break

        # no need to run query
        if not run_query:
            log.warn('No startmodes defined in {} and not manually monitored.  Terminating datasource collection.'.format(ds0.datasource))
            defer.returnValue(None)

        log.debug('{0}:Start Collection of Services'.format(config.id))

        WinRMQueries = [
            create_enum_info(
                'select name, state, status, displayname from Win32_Service'
            )
        ]

        conn_info = createConnectionInfo(ds0)

        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
    def collect(self, config):
        log.debug('{0}:Start Collection of IIS Sites'.format(config.id))
        ds0 = config.datasources[0]

        wql_iis6 = 'select ServerAutoStart from IIsWebServerSetting where name="{0}"'.format(
            ds0.params['statusname'])

        wql_iis7 = 'select ServerAutoStart from Site where name="{0}"'.format(
            ds0.params['statusname'])

        WinRMQueries = [
            create_enum_info(wql=wql_iis6, resource_uri=resource_uri_iis6),
            create_enum_info(wql=wql_iis7, resource_uri=resource_uri_iis7),
            ]

        conn_info = createConnectionInfo(ds0)
        winrm = WinrmCollectClient()
        results = None
        try:
            results = yield winrm.do_collect(conn_info, WinRMQueries)
        except Exception as e:
            log.error("IISSiteDataSource error on %s: %s",
                    config.id,
                    e)
        log.debug(WinRMQueries)
        defer.returnValue(results)
    def collect(self, config):

        log.info('{0}:Start Collection of Services'.format(config.id))
        ds0 = config.datasources[0]

        scheme = ds0.zWinScheme
        port = int(ds0.zWinRMPort)
        auth_type = 'kerberos' if '@' in ds0.zWinRMUser else 'basic'
        connectiontype = 'Keep-Alive'
        keytab = ds0.zWinKeyTabFilePath
        dcip = ds0.zWinKDC

        servicename = ds0.params['servicename']

        WinRMQueries = [
            create_enum_info('select name, state, status, displayname'\
             ' from Win32_Service where name = "{0}"'.format(servicename))]

        conn_info = ConnectionInfo(
            ds0.manageIp,
            auth_type,
            ds0.zWinRMUser,
            ds0.zWinRMPassword,
            scheme,
            port,
            connectiontype,
            keytab,
            dcip)
        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
Ejemplo n.º 5
0
    def collect(self, config):

        log.debug('{0}:Start Collection of Services'.format(config.id))

        WinRMQueries = [
            create_enum_info(
                'select name, state, status, displayname from Win32_Service')
        ]

        conn_info = createConnectionInfo(config.datasources[0])

        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)

        defer.returnValue(results)
Ejemplo n.º 6
0
    def collect(self, config):

        ds0 = config.datasources[0]

        log.debug('{0}:Start WinRM connection test.'.format(config.id))

        conn_info = createConnectionInfo(ds0)

        WinRMQueries = [
            create_enum_info('select * from Win32_OperatingSystem')
        ]

        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)

        defer.returnValue(results)
    def collect(self, config):

        ds0 = config.datasources[0]

        log.debug('{0}:Start WinRM connection test.'.format(config.id))

        conn_info = createConnectionInfo(ds0)

        WinRMQueries = [
            create_enum_info(
                'select * from Win32_OperatingSystem'
            )
        ]

        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)

        defer.returnValue(results)
Ejemplo n.º 8
0
    def collect(self, config):
        log.debug('{0}:Start Collection of IIS Sites'.format(config.id))
        ds0 = config.datasources[0]
        conn_info = createConnectionInfo(ds0)

        wql_iis6 = 'select ServerAutoStart from IIsWebServerSetting where name="{0}"'.format(
            ds0.params['statusname'])

        wql_iis7 = 'select ServerAutoStart from Site where name="{0}"'.format(
            ds0.params['statusname'])

        iis_version = ds0.params['iis_version']

        if not iis_version:
            winrs = IISCommander(conn_info)
            version = yield winrs.get_iis_version()
            # version should be in 'Version x.x' format
            # 7 and above use the same namespace/query
            try:
                iis_version = re.match('Version (\d).*',
                                       version.stdout[0]).group(1)
            except (IndexError, AttributeError):
                if version.stdout:
                    log.error("Malformed version information: {}".format(
                        version.stdout[0]))
                if version.stderr:
                    log.error("Error retrieving IIS Version: {}".format(
                        version.stderr[0]))
                defer.returnValue(None)

        if iis_version == 6:
            WinRMQueries = [
                create_enum_info(wql=wql_iis6, resource_uri=resource_uri_iis6)
            ]
        else:
            WinRMQueries = [
                create_enum_info(wql=wql_iis7, resource_uri=resource_uri_iis7)
            ]

        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)
        defer.returnValue(results)
    def collect(self, config):
        log.debug('{0}:Start Collection of IIS Sites'.format(config.id))
        ds0 = config.datasources[0]
        conn_info = createConnectionInfo(ds0)

        wql_iis6 = 'select ServerAutoStart from IIsWebServerSetting where name="{0}"'.format(
            ds0.params['statusname'])

        wql_iis7 = 'select ServerAutoStart from Site where name="{0}"'.format(
            ds0.params['statusname'])

        iis_version = ds0.params['iis_version']

        if not iis_version:
            winrs = IISCommander(conn_info)
            version = yield winrs.get_iis_version()
            # version should be in 'Version x.x' format
            # 7 and above use the same namespace/query
            try:
                iis_version = re.match('Version (\d).*', version.stdout[0]).group(1)
            except (IndexError, AttributeError):
                if version.stdout:
                    log.error("Malformed version information: {}".format(version.stdout[0]))
                if version.stderr:
                    log.error("Error retrieving IIS Version: {}".format(version.stderr[0]))
                defer.returnValue(None)

        if iis_version == 6:
            WinRMQueries = [create_enum_info(wql=wql_iis6, resource_uri=resource_uri_iis6),]
        else:
            WinRMQueries = [create_enum_info(wql=wql_iis7, resource_uri=resource_uri_iis7),]

        winrm = WinrmCollectClient()
        results = None
        try:
            results = yield winrm.do_collect(conn_info, WinRMQueries)
        except Exception as e:
            log.error("IISSiteDataSource error on %s: %s",
                    config.id,
                    e)
        log.debug(WinRMQueries)
        defer.returnValue(results)
Ejemplo n.º 10
0
    def collect(self, config):

        log.info('{0}:Start Collection of Services'.format(config.id))
        ds0 = config.datasources[0]

        servicename = ds0.params['servicename']

        WinRMQueries = [
            create_enum_info(
                'select name, state, status, displayname'
                ' from Win32_Service where name = "{0}"'.format(servicename))
        ]

        conn_info = createConnectionInfo(ds0)

        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
    def collect(self, config):

        ds0 = config.datasources[0]

        servicename = ds0.params['servicename']
        log.debug('{0}:Start Collection of Service {1}'.format(config.id, servicename))

        WinRMQueries = [
            create_enum_info(
                'select name, state, status, displayname'
                ' from Win32_Service where name = "{0}"'.format(servicename)
            )
        ]

        conn_info = createConnectionInfo(ds0)

        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
    def collect(self, config):
        log.debug('{0}:Start Collection of IIS Sites'.format(config.id))
        ds0 = config.datasources[0]

        wql_iis6 = 'select ServerAutoStart from IIsWebServerSetting where name="{0}"'.format(
            ds0.params['statusname'])

        wql_iis7 = 'select ServerAutoStart from Site where name="{0}"'.format(
            ds0.params['statusname'])

        WinRMQueries = [
            create_enum_info(wql=wql_iis6, resource_uri=resource_uri_iis6),
            create_enum_info(wql=wql_iis7, resource_uri=resource_uri_iis7),
            ]

        conn_info = createConnectionInfo(ds0)
        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
    def collect(self, config):
        log.debug("{0}:Start Collection of IIS Sites".format(config.id))
        ds0 = config.datasources[0]
        scheme = ds0.zWinScheme
        port = int(ds0.zWinRMPort)
        auth_type = "kerberos" if "@" in ds0.zWinRMUser else "basic"
        connectiontype = "Keep-Alive"
        keytab = ds0.zWinKeyTabFilePath
        dcip = ds0.zWinKDC

        wql = 'select ServerAutoStart from IIsWebServerSetting where name="{0}"'.format(ds0.params["statusname"])

        WinRMQueries = [create_enum_info(wql=wql, resource_uri=resource_uri)]

        conn_info = ConnectionInfo(
            ds0.manageIp, auth_type, ds0.zWinRMUser, ds0.zWinRMPassword, scheme, port, connectiontype, keytab, dcip
        )
        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
Ejemplo n.º 14
0
    def collect(self, config):
        log.debug('{0}:Start Collection of IIS Sites'.format(config.id))
        ds0 = config.datasources[0]
        scheme = ds0.zWinScheme
        port = int(ds0.zWinRMPort)
        auth_type = 'kerberos' if '@' in ds0.zWinRMUser else 'basic'
        connectiontype = 'Keep-Alive'
        keytab = ds0.zWinKeyTabFilePath
        dcip = ds0.zWinKDC

        wql = 'select ServerAutoStart from IIsWebServerSetting where name="{0}"'.format(
            ds0.params['statusname'])

        WinRMQueries = [create_enum_info(wql=wql, resource_uri=resource_uri)]

        conn_info = ConnectionInfo(ds0.manageIp, auth_type, ds0.zWinRMUser,
                                   ds0.zWinRMPassword, scheme, port,
                                   connectiontype, keytab, dcip)
        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
    def collect(self, config):

        ds0 = config.datasources[0]

        if ds0.params['startmode'] == 'None':
            log.debug('No startmodes defined in {}.  Terminating datasource collection.'.format(ds0.datasource))
            defer.returnValue(None)

        log.debug('{0}:Start Collection of Services'.format(config.id))

        WinRMQueries = [
            create_enum_info(
                'select name, state, status, displayname from Win32_Service'
            )
        ]

        conn_info = createConnectionInfo(ds0)

        winrm = WinrmCollectClient()
        results = yield winrm.do_collect(conn_info, WinRMQueries)
        log.debug(WinRMQueries)

        defer.returnValue(results)
Ejemplo n.º 16
0
class IIS(WinRMPlugin):
    compname = 'os'
    relname = 'winrmiis'
    modname = 'ZenPacks.zenoss.Microsoft.Windows.WinIIS'

    winrm = WinrmCollectClient()
    uri = 'http://schemas.microsoft.com/wbem/wsman/1/wmi/root/webadministration/*'

    queries = {
        'IIsWebServerSetting': {
            'query': "SELECT * FROM IIsWebServerSetting",
            'namespace': 'microsoftiisv2',
        },
        'IIsWebVirtualDirSetting': {
            'query': "SELECT * FROM IIsWebVirtualDirSetting",
            'namespace': 'microsoftiisv2',
        },
        'IIs7Site': {
            'query': "SELECT Name, Id, ServerAutoStart  FROM Site",
            'namespace': 'WebAdministration',
        },
    }

    @defer.inlineCallbacks
    def run_query(self, conn_info, wql, log):
        wql = create_enum_info(wql=wql, resource_uri=self.uri)
        result = yield self.winrm.do_collect(conn_info, [wql])
        defer.returnValue(result)

    @defer.inlineCallbacks
    def collect(self, device, log):
        orig = WinRMPlugin()
        orig.queries = self.queries
        conn_info = self.conn_info(device)
        output = yield orig.collect(device, log)
        for iisSite in output.get('IIs7Site', ()):
            name = iisSite.Name
            query = 'ASSOCIATORS OF {Site.Name="%s"} WHERE ResultClass=Application' % name
            result = yield self.run_query(conn_info, query, log)
            try:
                apps = result.values()[0][0]
                pool = apps.ApplicationPool
            except IndexError:
                pool = 'Unknown'
            iisSite.ApplicationPool = pool
        defer.returnValue(output)

    @save
    def process(self, device, results, log):
        log.info("Modeler %s processing data for device %s", self.name(),
                 device.id)

        rm = self.relMap()
        if results.get('IIsWebServerSetting'):
            for iisSite in results.get('IIsWebServerSetting', ()):
                om = self.objectMap()
                om.id = self.prepId(iisSite.Name)
                om.statusname = iisSite.Name
                om.title = iisSite.ServerComment
                om.iis_version = 6
                om.sitename = iisSite.ServerComment  # Default Web Site
                if iisSite.ServerAutoStart == 'false':
                    om.status = 'Stopped'
                else:
                    om.status = 'Running'

                for iisVirt in results.get('IIsWebVirtualDirSetting', ()):
                    if (iisVirt.Name == iisSite.Name +
                            "/ROOT") or (iisVirt.Name
                                         == iisSite.Name + "/root"):
                        om.apppool = iisVirt.AppPoolId

                rm.append(om)
        else:
            for iisSite in results.get('IIs7Site', ()):
                try:
                    om = self.objectMap()
                    om.id = self.prepId(iisSite.Id)
                    om.title = om.statusname = om.sitename = iisSite.Name
                    om.iis_version = 7
                    if iisSite.ServerAutoStart == 'false':
                        om.status = 'Stopped'
                    else:
                        om.status = 'Running'
                    om.apppool = iisSite.ApplicationPool
                    rm.append(om)
                except AttributeError:
                    pass

        return rm