Пример #1
0
 def _processPostcheck(self, parameters):
     '''
 '''
     resultCode, resultMessage = True, ""
     precheck_id = parameters["jobID"]
     taskList = TaskModel.find(**{"job_id": precheck_id})
     self.job.device_count = len(taskList)
     for task in taskList:
         device = DeviceModel.find_by_id(task.device_id)
         if not device:
             resultCode, resultMessage = False, "Device not found."
         self._hosts.append(device)
     return resultCode, resultMessage
    def RuleTask(self, task_id, event_type, column, value, rule):
        result = 0
        if rule["element"] == "task":
            rule_value = rule["value"]
            if rule.get("device") and rule.get("device") != 'None':
                rule_element = "device"
            if rule.get("deviceClass") and rule.get("deviceClass") != 'None':
                rule_element = "deviceClass"
            if rule.get("group") and rule.get("group") != 'None':
                rule_element = "group "
            if rule.get("location") and rule.get("location") != 'None':
                rule_element = "location"
            get_task = TaskModel.findById(task_id)
            task = get_task.__dict__
            get_device = DeviceModel.find_by_id(get_task.device_id)
            device = get_device.__dict__
            if device[rule_element] == rule.get(
                    rule_element) and rule_value == value:
                result = 1
            return result, device[rule_element], "status", rule_value

        if rule["element"] == "device":
            rule_column = rule["column"]
            rule_operation = rule["operation"]
            rule_value = rule["value"]
            get_task = TaskModel.findById(task_id)
            task = get_task.__dict__
            get_device = DeviceModel.find_by_id(get_task.device_id)
            device_name = get_device.name
            device = get_device.__dict__
            try:
                element_column = device[rule_column]
            except:
                return result, None, None, None
            result = self.comparison(element_column, rule_value,
                                     rule_operation)
            return result, device_name, rule_column, rule_value
        return result, None, None, None
Пример #3
0
 def ProcessCompliance(self, status):
   compliance_execution = ComplianceExecutionModel.find_by_id(self.job.compliance_execution_id)
   check_list = CheckModel.find(**{"compliance_id": compliance_execution.compliance_id})
   device_name = DeviceModel.find_by_id(TaskModel.findById(self.task.id).device_id).name
   if status == "SUCCESSFUL":
     total = 0
     for check in check_list:
       check_result = CheckResultModel(check.id, check.name, device_name, self.task.id, self.job.compliance_execution_id, status = 'NEW', parameters = {})
       check_result.save_to_db(commit=False)
       total, result_lines = self.ApplyChecks(self.task, check)
       if total == len(check.rules):
         check_result.status = "SUCCESSFUL"
         check_result.parameters["result"] = result_lines
       else:
         check_result.status = "FAILED"
         check_result.parameters["result"] = result_lines
       check_result.commit()
   elif status == "FAILED":
     for check in check_list:
       check_result = CheckResultModel(check.id, check.name, device_name, self.task.id, self.job.compliance_execution_id, status = 'NEW', parameters = {})
       check_result.save_to_db(commit=False)
       check_result.status = "FAILED"
       check_result.commit()
   return