/**
  * MYSQL_ADD_SLAVE action modifyer
  * @param string $actionId - action idenifyer
  * @param array $actionParams - action parameterss
  * @param string $hostname - server hostname
  * @return array - modifyed action params
  * @throws NeedMoreUserInfoException
  */
 public static function mysqlAddSlave($actionId, $actionParams, $hostname)
 {
     $action = new Action("MYSQL_ADD_SLAVE_MODIFYER", array("START_COMMAND_TEMPLATE" => "sudo -u root /opt/webdir/bin/bx-mysql -a options -o json", "LOG_LEVEL" => Logger::LOG_LEVEL_DISABLE), "", array());
     $action->start();
     $actRes = $action->getResult();
     $needModeInfo = false;
     if (isset($actRes["MYSQL_ADD_SLAVE_MODIFYER"]["OUTPUT"]["DATA"]["params"]["options"]) && is_array($actRes["MYSQL_ADD_SLAVE_MODIFYER"]["OUTPUT"]["DATA"]["params"]["options"])) {
         foreach ($actRes["MYSQL_ADD_SLAVE_MODIFYER"]["OUTPUT"]["DATA"]["params"]["options"] as $option) {
             if ($option == "cluster_password" || $option == "replica_password") {
                 $actionParams["START_COMMAND_TEMPLATE"] .= " --" . $option . "=" . \Bitrix\Scale\Helper::generatePass();
             } elseif ($option == "mysql_password") {
                 $actionParams["START_COMMAND_TEMPLATE"] .= " --" . $option . "=##USER_PARAMS:MYSQL_PASS##";
                 if (!isset($actionParams["USER_PARAMS"])) {
                     $actionParams["USER_PARAMS"] = array();
                 }
                 $actionParams["USER_PARAMS"]["MYSQL_PASS"] = array("NAME" => Loc::getMessage("SCALE_AM_MYAR_MYSQL_PASS"), "TYPE" => "PASSWORD", "REQUIRED" => "Y", "VERIFY_TWICE" => "Y");
                 $needModeInfo = true;
             }
         }
         if ($needModeInfo) {
             throw new NeedMoreUserInfoException("Need more user's info", $actionParams);
         }
     }
     return $actionParams;
 }
Exemple #2
0
 /**
  * Checks if monitoring is enabled
  * @return bool
  */
 public static function isEnabled()
 {
     $result = false;
     $command = "sudo -u root /opt/webdir/bin/bx-monitor -o json";
     try {
         $action = new Action("is_monitoring_enabled", array("START_COMMAND_TEMPLATE" => $command, "LOG_LEVEL" => Logger::LOG_LEVEL_DISABLE), "", array());
         if (!$action->start()) {
             return false;
         }
     } catch (\Exception $e) {
         return false;
     }
     $actRes = $action->getResult();
     if (isset($actRes["is_monitoring_enabled"]["OUTPUT"]["DATA"]["params"]["monitor"]["monitoring_status"])) {
         $result = $actRes["is_monitoring_enabled"]["OUTPUT"]["DATA"]["params"]["monitor"]["monitoring_status"] == "enable";
     } else {
         $result = false;
     }
     return $result;
 }
Exemple #3
0
 /**
  * @param array $condition
  * @return bool
  */
 protected static function isConditionSatisfied($condition)
 {
     $result = true;
     if (!isset($condition["COMMAND"]) || !isset($condition["PARAMS"]) || !is_array($condition["PARAMS"])) {
         return true;
     }
     if (!isset($condition["PARAMS"][0]) || !isset($condition["PARAMS"][1]) || !isset($condition["PARAMS"][2])) {
         return true;
     }
     try {
         $action = new Action("condition", array("START_COMMAND_TEMPLATE" => $condition["COMMAND"], "LOG_LEVEL" => Logger::LOG_LEVEL_DISABLE), "", array());
         if (!$action->start()) {
             return true;
         }
     } catch (\Exception $e) {
         return true;
     }
     $actRes = $action->getResult();
     if (isset($actRes["condition"]["OUTPUT"]["DATA"]["params"])) {
         $arParam = explode(":", $condition["PARAMS"][0]);
         $buildParam = $actRes["condition"]["OUTPUT"]["DATA"]["params"];
         foreach ($arParam as $param) {
             if (isset($buildParam[$param])) {
                 $buildParam = $buildParam[$param];
             }
         }
         $fBody = 'return ($param ' . $condition["PARAMS"][1] . ' ' . $condition["PARAMS"][2] . ');';
         $newfunc = create_function('$param', $fBody);
         $result = $newfunc($buildParam);
     }
     return $result;
 }