function hook_monitis_ServerDelete($vars) { require_once 'monitisapp.php'; $server_id = $vars['serverid']; // to change, add delete monitors monitisWhmcsServer::unlinkMonitorsByServersId($server_id); }
<?php require_once '../modules/addons/monitis_addon/lib/serverslisttab.class.php'; $oSrvrs = new serversListTab(); if (isset($_POST['create_NewMonitors']) && $_POST['create_NewMonitors'] > 0) { if (isset($_POST['serverId'])) { $servers = array_map("intval", $_POST['serverId']); $srv_ids = MonitisHelper::idsByField($servers, ''); $srv_ids_str = implode(",", $srv_ids); $srvs = monitisWhmcsServer::serverByIds($srv_ids_str); $ext = monitisWhmcsServer::extMonitorsByServerIds($srv_ids_str); $int = monitisWhmcsServer::intMonitorsByServerIds($srv_ids_str); $whmcs = array('ext' => $ext, 'int' => $int); MonitisConf::$settings['ping']['autocreate'] = 1; MonitisConf::$settings['cpu']['autocreate'] = 1; MonitisConf::$settings['memory']['autocreate'] = 1; for ($i = 0; $i < count($srvs); $i++) { $resp = MonitisApiHelper::addAllDefault(MONITIS_CLIENT_ID, $srvs[$i], $whmcs); $ping = $resp['ping']; $msg = 'Server ' . $srvs[$i][name] . ' - PING monitor: ' . $ping['msg']; if ($ping['status'] == 'error') { MonitisApp::addError($msg); } elseif ($ping['status'] == 'warning') { //MonitisApp::addWarning($msg); } if ($resp['agent']['status'] == 'ok') { $internalMonitors = $resp['internal_monitors']; foreach ($internalMonitors as $key => $val) { $msg = 'Server ' . $srvs[$i][name] . ' - ' . strtoupper($key) . ' monitor: ' . $internalMonitors[$key]['msg']; if ($internalMonitors[$key]['status'] == 'error') { MonitisApp::addError($msg);
private function toDo(&$data, $action, $hookType = '') { if (isset($data['products']) && count($data['products']) > 0) { $result = array('status' => 'ok', 'msg' => ''); $products = $data['products']; $arr = array(); for ($i = 0; $i < count($products); $i++) { $prdct = $products[$i]; $mon = $prdct['monitor']; $api = null; if ($mon) { $api = $mon['api']; } $rslt = null; switch ($action) { case 'active': case 'create': $status = ''; if ($prdct['producttype'] == 'addon') { $status = $this->addonStatus($prdct); } else { $status = $this->prdctStatus($data, $prdct); } if ($status) { if ($mon) { if ($api) { if ($api['isSuspended']) { $resp = monitisClientApi::activateExternal($mon); if (!$resp['error']) { $rslt = array('status' => 'ok', 'msg' => 'Monitor successfully activated'); } else { $rslt = array('status' => 'warning', 'msg' => $resp['error']); } } else { // edit $rslt = array('status' => 'warning', 'msg' => 'Monitor is exist and active'); } } else { // link $rslt = MonitisSeviceHelper::createMonitor($prdct); } } else { $rslt = MonitisSeviceHelper::createMonitor($prdct); } } else { $rslt = array('status' => 'error', 'msg' => 'Product status is inactive'); } break; case 'unlink': if ($mon) { $resp = monitisWhmcsServer::unlinkProductMonitorById($mon['monitor_id']); $rslt = array('status' => 'ok', 'msg' => 'Monitor unlinked successfully'); } else { $rslt = array('status' => 'warning', 'msg' => 'Monitor is not linked'); } break; case 'delete': if ($mon) { $resp = monitisClientApi::deleteExternalMonitor($mon); if ($resp['status'] == 'ok') { $rslt = array('status' => 'ok', 'msg' => 'Monitor deleted successfully'); } else { $rslt = array('status' => 'error', 'msg' => $resp['error']); } } else { $rslt = array('status' => 'warning', 'msg' => 'Monitor is not linked'); } break; case 'suspended': if ($mon) { $resp = monitisClientApi::suspendExternal($mon); if ($resp['status'] == 'ok') { if (@$resp['data']) { $rslt = array('status' => 'ok', 'msg' => $resp['data']); } else { $rslt = array('status' => 'ok', 'msg' => 'The monitor suspended successfully'); } } else { $rslt = array('status' => 'error', 'msg' => 'Error suspended'); } } else { $rslt = array('status' => 'warning', 'msg' => 'Monitor is not linked'); } break; } $arr[] = array('product' => $products[$i], 'response' => $rslt); } return $arr; } else { return null; } }
public function allSnapshots() { $whmcsExt = monitisWhmcsServer::ext_monitors(); if ($whmcsExt) { $this->whmcs_ext_ids = MonitisHelper::idsByField($whmcsExt, 'monitor_id'); } $this->whmcs_int = monitisWhmcsServer::int_monitors(); if ($this->whmcs_int) { $this->intSnapshotsIds(); } }
static function deleteExternalMonitor(&$monitor) { $monitor_id = $monitor['monitor_id']; $user = self::userToken($monitor['user_id']); if ($user['status'] == 'ok') { $params = array('testIds' => $monitor_id); $resp = self::requestPost('deleteExternalMonitor', $params, $user); if (@$resp['status'] == 'ok') { monitisWhmcsServer::unlinkExternalMonitorById($monitor_id); } return $resp; } else { return $user; } }
public function getServerInfo($server_id) { $server = monitisWhmcsServer::serverInfo($server_id); // all linked ping monitors $this->whmcsExt = monitisWhmcsServer::extMonitorsByServerIds($server['id']); // get all ping monitors $this->allPings = MonitisApi::getExternalMonitors(); if (@$this->allPings['status'] != 'error' && @$this->allPings['code'] != 101) { $this->pingsStatus = null; if ($this->allPings && isset($this->allPings['testList'])) { $this->allPings = $this->allPings['testList']; // get all ping monitors status $this->pingsStatus = MonitisApi::externalSnapshot(); } else { $this->allPings = null; } // all linked internal monitors $this->whmcsInt = monitisWhmcsServer::intMonitorsByServerIds($server['id']); if (!$this->whmcsInt) { $this->whmcsInt = array(); } $agent = $this->getAgent($server['hostname']); if ($agent && isset($agent['agentId'])) { $this->agentInfo = $agent; // get agent info $this->agentFullInfo = MonitisApi::getAgentInfo($agent['agentId'], true); } $server = $this->initServer($server); } return $server; }
public function initServers() { $allSrvrsIds = MonitisHelper::idsByField($this->whmcsAllServers, 'id'); $srvrsIds = implode(',', $allSrvrsIds); // all linked ping monitors // get all ping monitors $this->allPings = MonitisApi::getExternalMonitors(); // if Monitis server ok if (@$this->allPings['status'] != 'error' && @$this->allPings['code'] != 101) { // remove unlinked ping monitors from whmcs $this->whmcsExt = monitisWhmcsServer::extMonitorsByServerIds($srvrsIds); if ($this->allPings && isset($this->allPings['testList'])) { // get all ping monitors $this->allPings = $this->allPings['testList']; } else { $this->allPings = null; } // remove unlinked ping monitors from whmcs if ($this->whmcsExt) { $this->unlinkedPings(); } // all linked internal monitors $this->whmcsInt = monitisWhmcsServer::intMonitorsByServerIds($srvrsIds); if (!$this->whmcsInt) { $this->whmcsInt = array(); } // get agents $this->allAgents = MonitisApi::allAgentsSnapshot('', true); $this->init_all_servers(); } }
public function init($opts) { // all servers $this->synchronize = $opts['synchronize']; $this->whmcsAllServers = monitisWhmcsServer::allServers($opts); if ($this->whmcsAllServers) { $this->total = $this->whmcsAllServers[0]['total']; $this->initServers(); } return $this->whmcsAllServers; }
static function unlinkExternalMonitor($monitor_id) { monitisWhmcsServer::unlinkExternalMonitorById($monitor_id); return array('status' => 'ok'); }