Example #1
0
  private void logFailedStorageConnections(Map<String, String> returnValue) {
    StringBuilder failedDomainNames = new StringBuilder();
    String namesSeparator = ",";
    for (Entry<String, String> result : returnValue.entrySet()) {
      if (!"0".equals(result.getValue())) {
        List<StorageDomain> domains =
            DbFacade.getInstance()
                .getStorageDomainDao()
                .getAllByConnectionId(new Guid(result.getKey()));
        if (!domains.isEmpty()) {
          for (StorageDomain domain : domains) {
            if (failedDomainNames.length() > 0) {
              failedDomainNames.append(namesSeparator);
            }
            failedDomainNames.append(domain.getStorageName());
          }
        }
      }
    }

    if (failedDomainNames.length() > 0) {
      AuditLogableBase logable = new AuditLogableBase(getParameters().getVdsId());
      logable.addCustomValue("failedStorageDomains", failedDomainNames.toString());
      auditLogDirector.log(logable, AuditLogType.VDS_STORAGES_CONNECTION_FAILED);
    }
  }
  protected static void reportUnsupportedVnicProfileFeatures(
      VM vm,
      VmNic nic,
      VnicProfile vnicProfile,
      List<VNIC_PROFILE_PROPERTIES> unsupportedFeatures) {

    if (unsupportedFeatures.isEmpty()) {
      return;
    }

    AuditLogableBase event = new AuditLogableBase();
    event.setVmId(vm.getId());
    event.setVdsGroupId(vm.getVdsGroupId());
    event.setCustomId(nic.getId().toString());
    event.setCompatibilityVersion(vm.getVdsGroupCompatibilityVersion().toString());
    event.addCustomValue("NicName", nic.getName());
    event.addCustomValue("VnicProfile", vnicProfile == null ? null : vnicProfile.getName());
    String[] unsupportedFeatureNames = new String[unsupportedFeatures.size()];
    for (int i = 0; i < unsupportedFeatures.size(); i++) {
      unsupportedFeatureNames[i] = unsupportedFeatures.get(i).getFeatureName();
    }

    event.addCustomValue("UnsupportedFeatures", StringUtils.join(unsupportedFeatureNames, ", "));
    AuditLogDirector.log(event, AuditLogType.VNIC_PROFILE_UNSUPPORTED_FEATURES);
  }
  @Override
  public void runColdRebootVms(List<Guid> vmIds) {
    for (Guid vmId : vmIds) {
      AuditLogableBase event = new AuditLogableBase();
      event.setVmId(vmId);
      auditLogDirector.log(event, AuditLogType.COLD_REBOOT_VM_DOWN);

      log.info(
          "VM is down as a part of cold reboot process. Attempting to restart. VM Name '{}', VM Id '{}",
          event.getVmName(),
          vmId);
    }

    coldRebootAutoStartVmsRunner.addVmsToRun(vmIds);
  }
  @Override
  public void runFailedAutoStartVMs(List<Guid> vmIds) {
    for (Guid vmId : vmIds) {
      // Alert that the virtual machine failed:
      AuditLogableBase event = new AuditLogableBase();
      event.setVmId(vmId);
      auditLogDirector.log(event, AuditLogType.HA_VM_FAILED);

      log.info(
          "Highly Available VM went down. Attempting to restart. VM Name '{}', VM Id '{}'",
          event.getVmName(),
          vmId);
    }

    haAutoStartVmsRunner.addVmsToRun(vmIds);
  }
  @Override
  public void processOnClientIpChange(final Guid vmId, String newClientIp) {
    final AuditLogableBase event = new AuditLogableBase();
    final VmDynamic vmDynamic = DbFacade.getInstance().getVmDynamicDao().get(vmId);
    event.setVmId(vmId);
    event.setUserName(vmDynamic.getConsoleCurrentUserName());

    // in case of empty clientIp we clear the logged in user.
    // (this happened when user close the console to spice/vnc)
    if (StringUtils.isEmpty(newClientIp)) {
      vmDynamic.setConsoleCurrentUserName(null);
      DbFacade.getInstance().getVmDynamicDao().update(vmDynamic);
      auditLogDirector.log(event, AuditLogType.VM_CONSOLE_DISCONNECTED);
    } else {
      auditLogDirector.log(event, AuditLogType.VM_CONSOLE_CONNECTED);
    }
  }
Example #6
0
  private void cleanZombieTasks() {
    long maxTime =
        DateTime.getNow()
            .addMinutes(
                -1 * Config.<Integer>getValue(ConfigValues.AsyncTaskZombieTaskLifeInMinutes))
            .getTime();
    for (SPMTask task : _tasks.values()) {

      if (task.getParameters().getDbAsyncTask().getStartTime().getTime() < maxTime) {
        AuditLogableBase logable = Injector.injectMembers(new AuditLogableBase());
        logable.addCustomValue(
            "CommandName", task.getParameters().getDbAsyncTask().getActionType().toString());
        logable.addCustomValue(
            "Date", task.getParameters().getDbAsyncTask().getStartTime().toString());

        // if task is not finish and not unknown then it's in running
        // status
        if (task.getLastTaskStatus().getStatus() != AsyncTaskStatusEnum.finished
            && task.getLastTaskStatus().getStatus() != AsyncTaskStatusEnum.unknown) {
          // mark it as a zombie task, Will result in failure of the command
          task.setZombieTask(true);
          auditLogDirector.log(logable, AuditLogType.TASK_STOPPING_ASYNC_TASK);

          log.info(
              "Cleaning zombie tasks: Stopping async task '{}' that started at '{}'",
              task.getParameters().getDbAsyncTask().getActionType(),
              task.getParameters().getDbAsyncTask().getStartTime());

          task.stopTask(true);
        } else {
          auditLogDirector.log(logable, AuditLogType.TASK_CLEARING_ASYNC_TASK);

          log.info(
              "Cleaning zombie tasks: Clearing async task '{}' that started at '{}'",
              task.getParameters().getDbAsyncTask().getActionType(),
              task.getParameters().getDbAsyncTask().getStartTime());

          task.clearAsyncTask(true);
        }
      }
    }
  }
  private void logUnsynchronizedNetworks(VDS host, Map<String, Network> networks) {
    List<String> networkNames = new ArrayList<>();

    for (VdsNetworkInterface iface : host.getInterfaces()) {
      Network network = networks.get(iface.getNetworkName());

      NetworkImplementationDetails networkImplementationDetails =
          networkImplementationDetailsUtils.calculateNetworkImplementationDetails(iface, network);

      if (networkImplementationDetails != null
          && !networkImplementationDetails.isInSync()
          && networkImplementationDetails.isManaged()) {
        networkNames.add(iface.getNetworkName());
      }
    }

    if (!networkNames.isEmpty()) {
      AuditLogableBase logable = new AuditLogableBase(host.getId());
      logable.addCustomValue("Networks", StringUtils.join(networkNames, ","));
      auditLogDirector.log(logable, AuditLogType.VDS_NETWORKS_OUT_OF_SYNC);
    }
  }
 @Override
 public void setEntityId(AuditLogableBase logable) {
   logable.setVdsId(oldHost.getId());
 }