def check(self, instance):
        # Connect to the WMI provider
        host = instance.get('host', None)
        user = instance.get('username', None)
        password = instance.get('password', None)
        instance_tags = instance.get('tags', [])
        sites = instance.get('sites', ['_Total'])
        w = self._get_wmi_conn(host, user, password)

        try:
            wmi_cls = w.Win32_PerfFormattedData_W3SVC_WebService()
            if not wmi_cls:
                raise Exception('Missing data from Win32_PerfFormattedData_W3SVC_WebService')
        except Exception:
            self.log.exception('Unable to fetch Win32_PerfFormattedData_W3SVC_WebService class')
            return

        expected_sites = set(sites)
        # Iterate over every IIS site
        for iis_site in wmi_cls:
            # Skip any sites we don't specifically want.
            if iis_site.Name not in sites:
                continue

            # Tag with the site name if we're not using the aggregate
            if iis_site.Name != '_Total':
                tags = instance_tags + ['site:%s' % iis_site.Name]
            else:
                tags = instance_tags

            status = AgentCheck.CRITICAL if iis_site.ServiceUptime == 0 else AgentCheck.OK
            self.service_check("iis.site_up", status, tags=['site:%s' % iis_site.Name])
            expected_sites.remove(iis_site.Name)

            for metric, mtype, wmi_val in self.METRICS:
                if not hasattr(iis_site, wmi_val):
                    if wmi_val == 'TotalBytesTransferred' and hasattr(iis_site,
                                                                      'TotalBytesTransfered'):
                        # Windows 2008 sp2 reports it as TotalbytesTransfered
                        # instead of TotalBytesTransferred (single r)
                        wmi_val = 'TotalBytesTransfered'
                    elif wmi_val == 'TotalConnectionAttemptsAllInstances' \
                            and hasattr(iis_site, 'TotalConnectionAttemptsallinstances'):
                        wmi_val = 'TotalConnectionAttemptsallinstances'
                    else:
                        self.warning("Unable to fetch metric %s. Missing %s in "
                                     "Win32_PerfFormattedData_W3SVC_WebService"
                                     % (metric, wmi_val))
                        continue

                # Submit the metric value with the correct type
                value = float(getattr(iis_site, wmi_val))
                metric_func = getattr(self, mtype)
                metric_func(metric, value, tags=tags)

        for remaining_site in expected_sites:
            self.service_check("iis.site_up", AgentCheck.CRITICAL,
                               tags=['site:%s' % remaining_site])
dataset/ETHPy150Open serverdensity/sd-agent/checks.d/iis.py/IIS.check/original