Exemple #1
0
 public function getAgent($keyRegExp)
 {
     $agentInfo = null;
     $agentResp = MonitisApi::getAgent($keyRegExp);
     if ($agentResp) {
         $agent = $agentResp[0];
         $agentInfo = array('agentKey' => $agent['key'], 'agentId' => $agent['id'], 'name' => $keyRegExp, 'tag' => $keyRegExp . '_whmcs', 'status' => $agent['status'], 'platform' => $agent['platform']);
         $drives = $agent['drives'];
         if ($drives) {
             $list = array();
             $drv = array();
             for ($i = 0; $i < count($drives); $i++) {
                 $list[] = $drives[$i];
                 // $drives[$i][1]
                 $drv[] = array('letter' => $drives[$i]);
                 // $drives[$i][1]
             }
             $agentInfo['drivesList'] = implode(',', $list);
             $agentInfo['drives'] = $drv;
         }
     }
     return $agentInfo;
 }
Exemple #2
0
                 $pubKey = MonitisApi::monitorPublicKey(array('moduleType' => 'memory', 'monitorId' => $memory_monitorId));
                 $values = array("server_id" => $serverInfo['id'], "available" => MonitisConf::$settings['memory']['available'], "monitor_id" => $memory_monitorId, "agent_id" => $agentId, "monitor_type" => 'memory', "client_id" => MONITIS_CLIENT_ID, "publickey" => $pubKey);
                 insert_query('mod_monitis_int_monitors', $values);
                 MonitisApp::addMessage('Memory Monitor successfully created');
                 $serverInfo['agent']['memory'] = $serverMonitors->getMonitor($resp['data']['testId'], 'memory');
             } else {
                 MonitisApp::addError($resp['error']);
             }
         } else {
             MonitisApp::addError('This server agent does not have Memory');
         }
     }
     break;
 case 'drive':
     $hostname = $serverInfo['hostname'];
     $agents = MonitisApi::getAgent($hostname);
     $agentId = $agents[0]['id'];
     $agentKey = $agents[0]['key'];
     $platform = $agents[0]['platform'];
     $driveLetter = $_POST['driveLetter'];
     $freeLimit = $_POST['freeLimit'];
     if (isset($_POST['id'])) {
         $monitorId = (int) $_POST['id'];
         $params = array('testId' => $monitorId, 'freeLimit' => $freeLimit, 'name' => 'drive_' . $driveLetter . '@' . $serverInfo['hostname'], 'tag' => $serverInfo['hostname'] . '_whmcs');
         $resp = MonitisApi::editDriveMonitor($params);
         if ($resp) {
             if ($resp['status'] == 'ok') {
                 $pubKey = MonitisApi::monitorPublicKey(array('moduleType' => 'drive', 'monitorId' => $monitorId));
                 $values = array('server_id' => $serverInfo['id'], "available" => MonitisConf::$settings['drive']['available'], 'agent_id' => $agentId, 'monitor_id' => (int) $_POST['id'], 'monitor_type' => 'drive', 'client_id' => MONITIS_CLIENT_ID, "publickey" => $pubKey);
                 insert_query('mod_monitis_int_monitors', $values);
                 MonitisApp::addMessage('Drive Monitor successfully updated');
 static function addAllDefault($client_id, $server, $whmcs = null)
 {
     $response = array('ping' => array("status" => 'warning', "msg" => 'No autocreate'), 'agent' => array('status' => 'warning', 'msg' => 'The server does not have agent.'), 'internal_monitors' => array('drive' => array("status" => 'warning', "msg" => 'does not exist')));
     $external = null;
     $internal = null;
     if ($whmcs) {
         $external = isset($whmcs['ext']) && $whmcs['ext'] ? $whmcs['ext'] : null;
         $internal = isset($whmcs['int']) && $whmcs['int'] ? $whmcs['int'] : null;
     }
     if (MonitisConf::$settings['ping']['autocreate'] > 0) {
         // || MonitisConf::$settings['ping']['autolink'] > 0
         $response['ping'] = self::addDefaultPing($client_id, $server, $external);
     }
     $agents = MonitisApi::getAgent($server['hostname']);
     if ($agents && count($agents) > 0) {
         //$agents = $agents[0];
         if (isset($agents[0]['status']) && $agents[0]['status'] == 'running') {
             $response['agent'] = array('status' => 'ok', 'msg' => '');
             $resp = self::addDefaultAgents($client_id, $server, $internal, $agents);
             $response['internal_monitors']['cpu'] = $resp["cpu"];
             $response['internal_monitors']['memory'] = $resp["memory"];
             $oInt = new internalClass();
             $agentInfo = $oInt->getAgentInfo($server['hostname']);
             if ($agentInfo) {
                 $whmcs_drives = monitisWhmcsServer::intMonitorsByType($agentInfo['agentId'], 'drive');
                 $rep = $oInt->associateDrives($whmcs_drives, $agentInfo, $server['id']);
                 $response['internal_monitors']["drive"] = $rep;
             } else {
                 $response['internal_monitors']["drive"]["status"] = 'error';
                 $response['internal_monitors']["drive"]["msg"] = 'Agent error';
             }
         } else {
             $response['agent']['msg'] = 'Agent stopped';
             // link agent monitors
         }
     }
     monitisLog($response, 'addAllDefault - add All Default Monitors');
     return $response;
 }