def onSuccess(self, results, config): data = self.new_data() datasource_by_pid = {} metrics_by_component = collections.defaultdict( lambda: collections.defaultdict(list)) # Used for process restart checking. if not hasattr(self, 'previous_pids_by_component'): self.previous_pids_by_component = collections.defaultdict(set) pids_by_component = collections.defaultdict(set) sorted_datasource = sorted(config.datasources, key=lambda x: x.params.get('sequence', 0)) # Win32_Process: Counts and correlation to performance table. process_key = [x for x in results if 'Win32_Process' in x.wql][0] for item in results[process_key]: processText = get_processText(item) for datasource in sorted_datasource: regex = re.compile(datasource.params['regex']) # Zenoss 4.2 2013-10-15 RPS style. if 'replacement' in datasource.params: matcher = OSProcessDataMatcher( includeRegex=datasource.params['includeRegex'], excludeRegex=datasource.params['excludeRegex'], replaceRegex=datasource.params['replaceRegex'], replacement=datasource.params['replacement'], primaryUrlPath=datasource.params['primaryUrlPath'], generatedId=datasource.params['generatedId']) if not matcher.matches(processText): continue # Zenoss 4.2 intermediate style elif hasattr(OSProcess, 'matchRegex'): excludeRegex = re.compile( datasource.params['excludeRegex']) basic_match = OSProcess.matchRegex(regex, excludeRegex, processText) if not basic_match: continue capture_match = OSProcess.matchNameCaptureGroups( regex, processText, datasource.component) if not capture_match: continue # Zenoss 4.1-4.2 style. else: if datasource.params['ignoreParameters']: processText = item.ExecutablePath or item.Name name, args = get_processNameAndArgs(item) if datasource.params['ignoreParameters']: proc_id = getProcessIdentifier(name, None) else: proc_id = getProcessIdentifier(name, args) if datasource.component != prepId(proc_id): continue datasource_by_pid[item.ProcessId] = datasource pids_by_component[datasource.component].add(item.ProcessId) # Track process count. Append 1 each time we find a # match because the generic aggregator below will sum # them up to the total count. metrics_by_component[ datasource.component][COUNT_DATAPOINT].append(1) # Don't continue matching once a match is found. break # Send process status events. for datasource in config.datasources: component = datasource.component if COUNT_DATAPOINT in metrics_by_component[component]: severity = 0 summary = 'matching processes running' # Process restart checking. previous_pids = self.previous_pids_by_component.get(component) current_pids = pids_by_component.get(component) # No restart if there are no current or previous PIDs. # previous PIDs. if previous_pids and current_pids: # Only consider PID changes a restart if all PIDs # matching the process changed. if current_pids.isdisjoint(previous_pids): summary = 'matching processes restarted' # If the process is configured to alert on # restart, the first "up" won't be a clear. if datasource.params['alertOnRestart']: severity = datasource.params['severity'] else: severity = datasource.params['severity'] summary = 'no matching processes running' # Add a 0 count for process that aren't running. metrics_by_component[component][COUNT_DATAPOINT].append(0) data['events'].append({ 'device': datasource.device, 'component': component, 'eventClass': datasource.eventClass, 'eventGroup': 'Process', 'summary': summary, 'severity': severity, }) # Prepare for next cycle's restart check by merging current # process PIDs with previous. This is to catch restarts that # stretch across more than subsequent cycles. self.previous_pids_by_component.update( (c, p) for c, p in pids_by_component.iteritems() if p) # Win32_PerfFormattedData_PerfProc_Process: Datapoints. perf_keys = [x for x in results if 'Win32_Perf' in x.wql] if perf_keys: for item in results[perf_keys[0]]: if item.IDProcess not in datasource_by_pid: continue datasource = datasource_by_pid[item.IDProcess] for point in datasource.points: if point.id == COUNT_DATAPOINT: continue try: value = int(getattr(item, point.id)) except (TypeError, ValueError): LOG.warn("%s %s %s: Couldn't convert %r to integer", datasource.device, datasource.component, point.id, value) except AttributeError: LOG.warn("%s %s: %s not in result", datasource.device, datasource.component, point.id) else: metrics_by_component[datasource.component][ point.id].append(value) # Aggregate and store datapoint values. for component, points in metrics_by_component.iteritems(): for point, values in points.iteritems(): if point in NON_AGGREGATED_DATAPOINTS: value = values[0] else: value = sum(values) data['values'][component][point] = (value, 'N') # Send overall clear. data['events'].append({ 'device': config.id, 'severity': Event.Clear, 'eventClass': Status_OSProcess, 'summary': 'process scan successful', }) generateClearAuthEvents(config, data['events']) return data
def create_model_data(dmd): ''' Return an Endpoint suitable for Impact functional testing. ''' # DeviceClass dc = dmd.Devices.createOrganizer('/OpenStack/Infrastructure') dc.setZenProperty('zPythonClass', 'ZenPacks.zenoss.OpenStackInfrastructure.Endpoint') # OSProcessClasses osc = dmd.Processes.createOrganizer('/OpenStack') for binary in [ 'nova-cert', 'nova-conductor', 'nova-consoleauth', 'nova-scheduler', 'nova-compute', 'nova-api' ]: osc.manage_addOSProcessClass(binary) # Endpoint endpoint = dc.createInstance('endpoint') # API Endpoint for keystone from ZenPacks.zenoss.OpenStackInfrastructure.ApiEndpoint import ApiEndpoint keystone_apiendpoint = addContained( endpoint, "components", ApiEndpoint("apiendpoint-zOpenStackAuthUrl")) keystone_apiendpoint.url = 'http://127.0.0.1:5000/v2.0' keystone_apiendpoint.title = keystone_apiendpoint.url # non-public api endpoint for load balanced keystone keystone_apiendpoint2 = addContained( endpoint, "components", ApiEndpoint("apiendpoint-a8450514a5ca012fab799579ae4d7eec")) keystone_apiendpoint2.url = 'http://127.0.0.1:1234/v2.0' keystone_apiendpoint2.title = keystone_apiendpoint2.url # Org Structure from ZenPacks.zenoss.OpenStackInfrastructure.Region import Region from ZenPacks.zenoss.OpenStackInfrastructure.AvailabilityZone import AvailabilityZone region = addContained(endpoint, "components", Region("region")) zone1 = addContained(endpoint, "components", AvailabilityZone("zone1")) zone2 = addContained(endpoint, "components", AvailabilityZone("zone2")) addNonContained(region, "childOrgs", zone1) addNonContained(region, "childOrgs", zone2) # Tenants from ZenPacks.zenoss.OpenStackInfrastructure.Tenant import Tenant tenant1 = addContained(endpoint, "components", Tenant("tenant-tenant1")) tenant2 = addContained(endpoint, "components", Tenant("tenant-tenant2")) # Flavor from ZenPacks.zenoss.OpenStackInfrastructure.Flavor import Flavor flavor1 = addContained(endpoint, "components", Flavor("flavor1")) # Image from ZenPacks.zenoss.OpenStackInfrastructure.Image import Image image1 = addContained(endpoint, "components", Image("image1")) # Host from ZenPacks.zenoss.OpenStackInfrastructure.Host import Host computehost1 = addContained(endpoint, "components", Host("computehost1")) addNonContained(computehost1, "orgComponent", zone1) computehost2 = addContained(endpoint, "components", Host("computehost2")) addNonContained(computehost2, "orgComponent", zone2) controllerhost = addContained(endpoint, "components", Host("controllerhost")) addNonContained(controllerhost, "orgComponent", zone1) # SoftwareComponents from ZenPacks.zenoss.OpenStackInfrastructure.NovaService import NovaService from ZenPacks.zenoss.OpenStackInfrastructure.NovaApi import NovaApi nova_consoleauth = addContained(endpoint, "components", NovaService("nova-consoleauth")) nova_consoleauth.binary = 'nova-consoleauth' addNonContained(nova_consoleauth, "hostedOn", controllerhost) addNonContained(nova_consoleauth, "orgComponent", zone1) nova_scheduler = addContained(endpoint, "components", NovaService("nova-scheduler")) nova_scheduler.binary = 'nova-scheduler' addNonContained(nova_scheduler, "hostedOn", controllerhost) addNonContained(nova_scheduler, "orgComponent", zone1) nova_conductor1 = addContained(endpoint, "components", NovaService("nova-conductor1")) nova_conductor1.binary = 'nova-conductor' nova_conductor2 = addContained(endpoint, "components", NovaService("nova-conductor2")) nova_conductor2.binary = 'nova-conductor' addNonContained(nova_conductor1, "hostedOn", computehost1) addNonContained(nova_conductor1, "orgComponent", zone1) addNonContained(nova_conductor2, "hostedOn", computehost2) addNonContained(nova_conductor2, "orgComponent", zone2) nova_compute1 = addContained(endpoint, "components", NovaService("nova-compute1")) nova_compute1.binary = 'nova-compute' nova_compute2 = addContained(endpoint, "components", NovaService("nova-compute2")) nova_compute2.binary = 'nova-compute' addNonContained(nova_compute1, "hostedOn", computehost1) addNonContained(nova_compute1, "orgComponent", zone1) addNonContained(nova_compute2, "hostedOn", computehost2) addNonContained(nova_compute2, "orgComponent", zone2) nova_cert = addContained(endpoint, "components", NovaService("nova-cert")) nova_cert.binary = 'nova-cert' addNonContained(nova_cert, "hostedOn", controllerhost) addNonContained(nova_cert, "orgComponent", zone1) nova_api = addContained(endpoint, "components", NovaApi("nova-api")) nova_api.binary = 'nova-api' addNonContained(nova_api, "hostedOn", controllerhost) addNonContained(nova_api, "orgComponent", region) # Hypervisor from ZenPacks.zenoss.OpenStackInfrastructure.Hypervisor import Hypervisor hypervisor1 = addContained(endpoint, "components", Hypervisor("hypervisor1")) hypervisor2 = addContained(endpoint, "components", Hypervisor("hypervisor2")) addNonContained(hypervisor1, "host", computehost1) addNonContained(hypervisor2, "host", computehost2) # Instance from ZenPacks.zenoss.OpenStackInfrastructure.Instance import Instance instance1 = addContained(endpoint, "components", Instance("instance1")) instance2 = addContained(endpoint, "components", Instance("instance2")) instance3 = addContained(endpoint, "components", Instance("instance3")) instance4 = addContained(endpoint, "components", Instance("instance4")) addNonContained(instance1, "flavor", flavor1) addNonContained(instance2, "flavor", flavor1) addNonContained(instance3, "flavor", flavor1) addNonContained(instance4, "flavor", flavor1) addNonContained(instance1, "image", image1) addNonContained(instance2, "image", image1) addNonContained(instance3, "image", image1) addNonContained(instance4, "image", image1) addNonContained(instance1, "hypervisor", hypervisor1) addNonContained(instance2, "hypervisor", hypervisor1) addNonContained(instance3, "hypervisor", hypervisor2) addNonContained(instance4, "hypervisor", hypervisor2) addNonContained(instance1, "tenant", tenant1) addNonContained(instance2, "tenant", tenant2) addNonContained(instance3, "tenant", tenant1) addNonContained(instance4, "tenant", tenant2) # Vnic from ZenPacks.zenoss.OpenStackInfrastructure.Vnic import Vnic instance1vnic1 = addContained(instance1, "vnics", Vnic("instance1_vnic1")) instance1vnic1.macaddress = 'de:ad:be:ef:01:01' instance1vnic1.index_object() instance1vnic2 = addContained(instance1, "vnics", Vnic("instance1_vnic2")) instance1vnic2.macaddress = 'de:ad:be:ef:01:02' instance1vnic2.index_object() instance2vnic1 = addContained(instance2, "vnics", Vnic("instance2_vnic1")) instance2vnic1.macaddress = 'de:ad:be:ef:02:01' instance2vnic1.index_object() instance2vnic2 = addContained(instance2, "vnics", Vnic("instance2_vnic2")) instance2vnic2.macaddress = 'de:ad:be:ef:02:02' instance2vnic2.index_object() instance3vnic1 = addContained(instance3, "vnics", Vnic("instance3_vnic1")) instance3vnic1.macaddress = 'de:ad:be:ef:03:01' instance3vnic1.index_object() instance3vnic2 = addContained(instance3, "vnics", Vnic("instance3_vnic2")) instance3vnic2.macaddress = 'de:ad:be:ef:03:02' instance3vnic2.index_object() instance4vnic1 = addContained(instance4, "vnics", Vnic("instance4_vnic1")) instance4vnic1.macaddress = 'de:ad:be:ef:04:01' instance4vnic1.index_object() instance4vnic2 = addContained(instance4, "vnics", Vnic("instance4_vnic2")) instance4vnic2.macaddress = 'de:ad:be:ef:04:02' instance4vnic2.index_object() # Linux guest devices (Virtual) # make sure that the interfaces line up. guest_dc = dmd.Devices.createOrganizer('/Server/SSH/Linux') guest_dc.setZenProperty('zPythonClass', 'Products.ZenModel.Device') guest_instance1 = guest_dc.createInstance("g-instance1") guest_instance2 = guest_dc.createInstance("g-instance2") guest_instance3 = guest_dc.createInstance("g-instance3") # instance4 is not monitored by zenoss. from Products.ZenModel.IpInterface import IpInterface def add_linux_interface_mac(device, interface_name, macaddress): eth_if = IpInterface(interface_name) device.os.interfaces._setObject(eth_if.id, eth_if) eth_if = device.os.interfaces._getOb(eth_if.id) eth_if.macaddress = macaddress eth_if.index_object() device.index_object() add_linux_interface_mac(guest_instance1, 'eth0', 'de:ad:be:ef:01:01') add_linux_interface_mac(guest_instance1, 'eth1', 'de:ad:be:ef:01:02') add_linux_interface_mac(guest_instance2, 'eth0', 'de:ad:be:ef:02:01') add_linux_interface_mac(guest_instance2, 'eth1', 'de:ad:be:ef:02:02') add_linux_interface_mac(guest_instance3, 'eth0', 'de:ad:be:ef:03:01') add_linux_interface_mac(guest_instance3, 'eth1', 'de:ad:be:ef:03:02') # Linux devices (Physical) # (link to host1 and host2) phys_dc = dmd.Devices.createOrganizer('/Server/SSH/Linux/NovaHost') phys_dc.setZenProperty('zPythonClass', 'Products.ZenModel.Device') phys_computehost1 = phys_dc.createInstance("p-computehost1") phys_computehost2 = phys_dc.createInstance("p-computehost2") phys_controllerhost = phys_dc.createInstance("p-controllerhost") # Link the host components to the physical hosts. computehost1.claim_proxy_device(phys_computehost1) computehost2.claim_proxy_device(phys_computehost2) controllerhost.claim_proxy_device(phys_controllerhost) # Add OSprocesses for each of the software components. from ZenPacks.zenoss.OpenStackInfrastructure.SoftwareComponent import SoftwareComponent from Products.ZenModel.OSProcess import OSProcess for component in endpoint.components(): if isinstance(component, SoftwareComponent): binary = component.binary linux_device = component.hostedOn().ensure_proxy_device() process_id = '%s_%s' % (linux_device.id, binary) process = OSProcess(process_id) linux_device.os.processes._setObject(process_id, process) process = linux_device.os.processes._getOb(process_id) process_class = re.sub(r'\d+$', '', binary) process.setOSProcessClass( "Processes/OpenStack/osProcessClasses/%s" % process_class) # Cinder from ZenPacks.zenoss.OpenStackInfrastructure.Volume import Volume from ZenPacks.zenoss.OpenStackInfrastructure.VolSnapshot import VolSnapshot volume1 = addContained(endpoint, "components", Volume("volume1")) volsnap1 = addContained(endpoint, "components", VolSnapshot("volsnap1")) addNonContained(instance1, "volumes", volume1) addNonContained(volume1, "volSnapshots", volsnap1) return {'endpoint': endpoint, 'phys_dc': phys_dc, 'guest_dc': guest_dc}
def create_model_data(dmd): ''' Return an Endpoint suitable for Impact functional testing. ''' # DeviceClass dc = dmd.Devices.createOrganizer('/OpenStack/Infrastructure') dc.setZenProperty('zPythonClass', 'ZenPacks.zenoss.OpenStackInfrastructure.Endpoint') # OSProcessClasses osc = dmd.Processes.createOrganizer('/OpenStack') for binary in ['nova-cert', 'nova-conductor', 'nova-consoleauth', 'nova-scheduler', 'nova-compute', 'nova-api']: osc.manage_addOSProcessClass(binary) # Endpoint endpoint = dc.createInstance('endpoint') # Org Structure from ZenPacks.zenoss.OpenStackInfrastructure.Region import Region from ZenPacks.zenoss.OpenStackInfrastructure.AvailabilityZone import AvailabilityZone region = addContained(endpoint, "components", Region("region")) zone1 = addContained(endpoint, "components", AvailabilityZone("zone1")) zone2 = addContained(endpoint, "components", AvailabilityZone("zone2")) addNonContained(region, "childOrgs", zone1) addNonContained(region, "childOrgs", zone2) # Tenants from ZenPacks.zenoss.OpenStackInfrastructure.Tenant import Tenant tenant1 = addContained(endpoint, "components", Tenant("tenant-tenant1")) tenant2 = addContained(endpoint, "components", Tenant("tenant-tenant2")) # Flavor from ZenPacks.zenoss.OpenStackInfrastructure.Flavor import Flavor flavor1 = addContained(endpoint, "components", Flavor("flavor1")) # Image from ZenPacks.zenoss.OpenStackInfrastructure.Image import Image image1 = addContained(endpoint, "components", Image("image1")) # Host from ZenPacks.zenoss.OpenStackInfrastructure.Host import Host computehost1 = addContained(endpoint, "components", Host("computehost1")) addNonContained(computehost1, "orgComponent", zone1) computehost2 = addContained(endpoint, "components", Host("computehost2")) addNonContained(computehost2, "orgComponent", zone2) controllerhost = addContained(endpoint, "components", Host("controllerhost")) addNonContained(controllerhost, "orgComponent", zone1) # SoftwareComponents from ZenPacks.zenoss.OpenStackInfrastructure.NovaService import NovaService from ZenPacks.zenoss.OpenStackInfrastructure.NovaApi import NovaApi nova_consoleauth = addContained(endpoint, "components", NovaService("nova-consoleauth")) nova_consoleauth.binary = 'nova-consoleauth' addNonContained(nova_consoleauth, "hostedOn", controllerhost) addNonContained(nova_consoleauth, "orgComponent", zone1) nova_scheduler = addContained(endpoint, "components", NovaService("nova-scheduler")) nova_scheduler.binary = 'nova-scheduler' addNonContained(nova_scheduler, "hostedOn", controllerhost) addNonContained(nova_scheduler, "orgComponent", zone1) nova_conductor1 = addContained(endpoint, "components", NovaService("nova-conductor1")) nova_conductor1.binary = 'nova-conductor' nova_conductor2 = addContained(endpoint, "components", NovaService("nova-conductor2")) nova_conductor2.binary = 'nova-conductor' addNonContained(nova_conductor1, "hostedOn", computehost1) addNonContained(nova_conductor1, "orgComponent", zone1) addNonContained(nova_conductor2, "hostedOn", computehost2) addNonContained(nova_conductor2, "orgComponent", zone2) nova_compute1 = addContained(endpoint, "components", NovaService("nova-compute1")) nova_compute1.binary = 'nova-compute' nova_compute2 = addContained(endpoint, "components", NovaService("nova-compute2")) nova_compute2.binary = 'nova-compute' addNonContained(nova_compute1, "hostedOn", computehost1) addNonContained(nova_compute1, "orgComponent", zone1) addNonContained(nova_compute2, "hostedOn", computehost2) addNonContained(nova_compute2, "orgComponent", zone2) nova_cert = addContained(endpoint, "components", NovaService("nova-cert")) nova_cert.binary = 'nova-cert' addNonContained(nova_cert, "hostedOn", controllerhost) addNonContained(nova_cert, "orgComponent", zone1) nova_api = addContained(endpoint, "components", NovaApi("nova-api")) nova_api.binary = 'nova-api' addNonContained(nova_api, "hostedOn", controllerhost) addNonContained(nova_api, "orgComponent", region) # Hypervisor from ZenPacks.zenoss.OpenStackInfrastructure.Hypervisor import Hypervisor hypervisor1 = addContained(endpoint, "components", Hypervisor("hypervisor1")) hypervisor2 = addContained(endpoint, "components", Hypervisor("hypervisor2")) addNonContained(hypervisor1, "host", computehost1) addNonContained(hypervisor2, "host", computehost2) # Instance from ZenPacks.zenoss.OpenStackInfrastructure.Instance import Instance instance1 = addContained(endpoint, "components", Instance("instance1")) instance2 = addContained(endpoint, "components", Instance("instance2")) instance3 = addContained(endpoint, "components", Instance("instance3")) instance4 = addContained(endpoint, "components", Instance("instance4")) addNonContained(instance1, "flavor", flavor1) addNonContained(instance2, "flavor", flavor1) addNonContained(instance3, "flavor", flavor1) addNonContained(instance4, "flavor", flavor1) addNonContained(instance1, "image", image1) addNonContained(instance2, "image", image1) addNonContained(instance3, "image", image1) addNonContained(instance4, "image", image1) addNonContained(instance1, "hypervisor", hypervisor1) addNonContained(instance2, "hypervisor", hypervisor1) addNonContained(instance3, "hypervisor", hypervisor2) addNonContained(instance4, "hypervisor", hypervisor2) addNonContained(instance1, "tenant", tenant1) addNonContained(instance2, "tenant", tenant2) addNonContained(instance3, "tenant", tenant1) addNonContained(instance4, "tenant", tenant2) # Vnic from ZenPacks.zenoss.OpenStackInfrastructure.Vnic import Vnic instance1vnic1 = addContained(instance1, "vnics", Vnic("instance1_vnic1")) instance1vnic1.macaddress = 'de:ad:be:ef:01:01' instance1vnic1.index_object() instance1vnic2 = addContained(instance1, "vnics", Vnic("instance1_vnic2")) instance1vnic2.macaddress = 'de:ad:be:ef:01:02' instance1vnic2.index_object() instance2vnic1 = addContained(instance2, "vnics", Vnic("instance2_vnic1")) instance2vnic1.macaddress = 'de:ad:be:ef:02:01' instance2vnic1.index_object() instance2vnic2 = addContained(instance2, "vnics", Vnic("instance2_vnic2")) instance2vnic2.macaddress = 'de:ad:be:ef:02:02' instance2vnic2.index_object() instance3vnic1 = addContained(instance3, "vnics", Vnic("instance3_vnic1")) instance3vnic1.macaddress = 'de:ad:be:ef:03:01' instance3vnic1.index_object() instance3vnic2 = addContained(instance3, "vnics", Vnic("instance3_vnic2")) instance3vnic2.macaddress = 'de:ad:be:ef:03:02' instance3vnic2.index_object() instance4vnic1 = addContained(instance4, "vnics", Vnic("instance4_vnic1")) instance4vnic1.macaddress = 'de:ad:be:ef:04:01' instance4vnic1.index_object() instance4vnic2 = addContained(instance4, "vnics", Vnic("instance4_vnic2")) instance4vnic2.macaddress = 'de:ad:be:ef:04:02' instance4vnic2.index_object() # Linux guest devices (Virtual) # make sure that the interfaces line up. guest_dc = dmd.Devices.createOrganizer('/Server/SSH/Linux') guest_dc.setZenProperty('zPythonClass', 'Products.ZenModel.Device') guest_instance1 = guest_dc.createInstance("g-instance1") guest_instance2 = guest_dc.createInstance("g-instance2") guest_instance3 = guest_dc.createInstance("g-instance3") # instance4 is not monitored by zenoss. from Products.ZenModel.IpInterface import IpInterface def add_linux_interface_mac(device, interface_name, macaddress): eth_if = IpInterface(interface_name) device.os.interfaces._setObject(eth_if.id, eth_if) eth_if = device.os.interfaces._getOb(eth_if.id) eth_if.macaddress = macaddress eth_if.index_object() device.index_object() add_linux_interface_mac(guest_instance1, 'eth0', 'de:ad:be:ef:01:01') add_linux_interface_mac(guest_instance1, 'eth1', 'de:ad:be:ef:01:02') add_linux_interface_mac(guest_instance2, 'eth0', 'de:ad:be:ef:02:01') add_linux_interface_mac(guest_instance2, 'eth1', 'de:ad:be:ef:02:02') add_linux_interface_mac(guest_instance3, 'eth0', 'de:ad:be:ef:03:01') add_linux_interface_mac(guest_instance3, 'eth1', 'de:ad:be:ef:03:02') # Linux devices (Physical) # (link to host1 and host2) phys_dc = dmd.Devices.createOrganizer('/Server/SSH/Linux/NovaHost') phys_dc.setZenProperty('zPythonClass', 'Products.ZenModel.Device') phys_computehost1 = phys_dc.createInstance("p-computehost1") phys_computehost2 = phys_dc.createInstance("p-computehost2") phys_controllerhost = phys_dc.createInstance("p-controllerhost") # Link the host components to the physical hosts. computehost1.claim_proxy_device(phys_computehost1) computehost2.claim_proxy_device(phys_computehost2) controllerhost.claim_proxy_device(phys_controllerhost) # Add OSprocesses for each of the software components. from ZenPacks.zenoss.OpenStackInfrastructure.SoftwareComponent import SoftwareComponent from Products.ZenModel.OSProcess import OSProcess for component in endpoint.components(): if isinstance(component, SoftwareComponent): binary = component.binary linux_device = component.hostedOn().proxy_device() process_id = '%s_%s' % (linux_device.id, binary) process = OSProcess(process_id) linux_device.os.processes._setObject(process_id, process) process = linux_device.os.processes._getOb(process_id) process_class = re.sub(r'\d+$', '', binary) process.setOSProcessClass("Processes/OpenStack/osProcessClasses/%s" % process_class) # Cinder from ZenPacks.zenoss.OpenStackInfrastructure.Volume import Volume from ZenPacks.zenoss.OpenStackInfrastructure.VolSnapshot import VolSnapshot volume1 = addContained(endpoint, "components", Volume("volume1")) volsnap1 = addContained(endpoint, "components", VolSnapshot("volsnap1")) addNonContained(instance1, "volumes", volume1) addNonContained(volume1, "volSnapshots", volsnap1) return { 'endpoint': endpoint, 'phys_dc': phys_dc, 'guest_dc': guest_dc }
def onSuccess(self, results, config): data = self.new_data() datasource_by_pid = {} metrics_by_component = collections.defaultdict( lambda: collections.defaultdict(list)) # Used for process restart checking. if not hasattr(self, 'previous_pids_by_component'): self.previous_pids_by_component = collections.defaultdict(set) pids_by_component = collections.defaultdict(set) # Win32_Process: Counts and correlation to performance table. process_key = [x for x in results if 'Win32_Process' in x.wql][0] for item in results[process_key]: processText = get_processText(item) for datasource in config.datasources: regex = re.compile(datasource.params['regex']) # Zenoss 4.2 2013-10-15 RPS style. if 'replacement' in datasource.params: matcher = OSProcessDataMatcher( includeRegex=datasource.params['includeRegex'], excludeRegex=datasource.params['excludeRegex'], replaceRegex=datasource.params['replaceRegex'], replacement=datasource.params['replacement'], primaryUrlPath=datasource.params['primaryUrlPath'], generatedId=datasource.params['generatedId']) if not matcher.matches(processText): continue # Zenoss 4.2 intermediate style elif hasattr(OSProcess, 'matchRegex'): excludeRegex = re.compile( datasource.params['excludeRegex']) basic_match = OSProcess.matchRegex( regex, excludeRegex, processText) if not basic_match: continue capture_match = OSProcess.matchNameCaptureGroups( regex, processText, datasource.component) if not capture_match: continue # Zenoss 4.1-4.2 style. else: if datasource.params['ignoreParameters']: processText = item.ExecutablePath or item.Name name, args = get_processNameAndArgs(item) if datasource.params['ignoreParameters']: proc_id = getProcessIdentifier(name, None) else: proc_id = getProcessIdentifier(name, args) if datasource.component != prepId(proc_id): continue datasource_by_pid[item.ProcessId] = datasource pids_by_component[datasource.component].add(item.ProcessId) # Track process count. Append 1 each time we find a # match because the generic aggregator below will sum # them up to the total count. metrics_by_component[datasource.component][COUNT_DATAPOINT].append(1) # Send process status events. for datasource in config.datasources: component = datasource.component if COUNT_DATAPOINT in metrics_by_component[component]: severity = 0 summary = 'matching processes running' # Process restart checking. previous_pids = self.previous_pids_by_component.get(component) current_pids = pids_by_component.get(component) # No restart if there are no current or previous PIDs. # previous PIDs. if previous_pids and current_pids: # Only consider PID changes a restart if all PIDs # matching the process changed. if current_pids.isdisjoint(previous_pids): summary = 'matching processes restarted' # If the process is configured to alert on # restart, the first "up" won't be a clear. if datasource.params['alertOnRestart']: severity = datasource.params['severity'] else: severity = datasource.params['severity'] summary = 'no matching processes running' # Add a 0 count for process that aren't running. metrics_by_component[component][COUNT_DATAPOINT].append(0) data['events'].append({ 'device': datasource.device, 'component': component, 'eventClass': datasource.eventClass, 'eventGroup': 'Process', 'summary': summary, 'severity': severity, }) # Prepare for next cycle's restart check by merging current # process PIDs with previous. This is to catch restarts that # stretch across more than subsequent cycles. self.previous_pids_by_component.update( (c, p) for c, p in pids_by_component.iteritems() if p) # Win32_PerfFormattedData_PerfProc_Process: Datapoints. perf_key = [x for x in results if 'Win32_Perf' in x.wql][0] for item in results[perf_key]: if item.IDProcess not in datasource_by_pid: continue datasource = datasource_by_pid[item.IDProcess] for point in datasource.points: if point.id == COUNT_DATAPOINT: continue try: value = int(getattr(item, point.id)) except (TypeError, ValueError): LOG.warn( "%s %s %s: Couldn't convert %r to integer", datasource.device, datasource.component, point.id, value) except AttributeError: LOG.warn( "%s %s: %s not in result", datasource.device, datasource.component, point.id) else: metrics_by_component[datasource.component][point.id].append(value) # Aggregate and store datapoint values. for component, points in metrics_by_component.iteritems(): for point, values in points.iteritems(): if point in NON_AGGREGATED_DATAPOINTS: value = values[0] else: value = sum(values) data['values'][component][point] = (value, 'N') # Send overall clear. data['events'].append({ 'device': config.id, 'severity': Event.Clear, 'eventClass': Status_OSProcess, 'summary': 'process scan successful', }) return data
def getClassObject(self): return BaseOSProcess.getClassObject(self)