ProcessBuilder getProcessBuilder(String script, AlertNotification notification) {
    if (script == null || script.isEmpty()) {
      throw new IllegalArgumentException("Script path cannot be null or empty");
    }

    String unixPathRegex = "^(/[a-zA-Z0-9._-]+)+$";
    String windowsPathRegex = "^[a-zA-Z]:\\\\([a-zA-Z0-9._-]+\\\\?)+$";

    boolean isValidPath = SystemUtils.IS_OS_WINDOWS
            ? script.matches(windowsPathRegex)
            : script.matches(unixPathRegex);

    if (!isValidPath) {
      throw new IllegalArgumentException("Invalid script path format: " + script);
    }

    Path scriptPath = Paths.get(script);

    if (!scriptPath.isAbsolute()) {
      throw new IllegalArgumentException("Script path must be an absolute path: " + script);
    }

    if (!Files.exists(scriptPath)) {
      throw new IllegalArgumentException("Script does not exist: " + script);
    }

    if (!Files.isExecutable(scriptPath)) {
      throw new IllegalArgumentException("Script is not executable: " + script);
    }


    final String shellCommand;
    final String shellCommandOption;
    if (SystemUtils.IS_OS_WINDOWS) {
      shellCommand = "cmd";
      shellCommandOption = "/c";
    } else {
      shellCommand = "sh";
      shellCommandOption = "-c";
    }

    AlertInfo alertInfo = notification.getAlertInfo();
    AlertDefinitionEntity definition = alertInfo.getAlertDefinition();
    String definitionName = definition.getDefinitionName();
    AlertState alertState = alertInfo.getAlertState();
    String serviceName = alertInfo.getServiceName();

    // these could have spaces in them, so quote them so they don't mess up the
    // command line
    String alertLabel = "\"" + SHELL_ESCAPE.escape(definition.getLabel()) + "\"";
    String alertText = "\"" + SHELL_ESCAPE.escape(alertInfo.getAlertText()) + "\"";

    long alertTimestamp = alertInfo.getAlertTimestamp();
    String hostName = alertInfo.getHostName(); // null if alert do not run against host

    Object[] params = new Object[] { script, definitionName, alertLabel, serviceName,
        alertState.name(), alertText, alertTimestamp, hostName};

    String foo = StringUtils.join(params, " ");

    // sh -c '/foo/sys_logger.py ambari_server_agent_heartbeat "Agent Heartbeat"
    // AMBARI CRITICAL "Something went wrong with the host" 1111111 host222'
    return new ProcessBuilder(shellCommand, shellCommandOption, foo);
  }
Gets a {@link ProcessBuilder} initialized with a script command to run with
the parameters from the notification.

@param script
         the absolute path to the script (not {@code null}).
@param notification
         the notification to parameterie (not {@code null}).
@return
ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java