public function createDefaultGroup() { $defaultgroups = json_decode(MONITIS_ADMIN_CONTACT_GROUPS, true); $existedGroups = MonitisApi::getContactGroupList(); // existed monitis groups foreach ($defaultgroups as $mType => $groupName) { $group = MonitisHelper::in_array($existedGroups, 'id', MonitisConf::$settings['groups'][$mType]['groupId']); $alerts = json_decode(MONITIS_NOTIFICATION_RULE, true); if ($mType == 'internal') { $alerts['minFailedLocationCount'] = null; } $groupId = $group['id'] ? $group['id'] : 0; $notifByTypeGroup = MonitisApiHelper::getNotificationRuleByType($mType, $groupId); $alertRulesDefault = $notifByTypeGroup ? $notifByTypeGroup : $alerts; if ($group) { MonitisConf::$settings['groups'][$mType]['groupId'] = $group['id']; MonitisConf::$settings['groups'][$mType]['groupName'] = $group['name']; MonitisConf::$settings['groups'][$mType]['alert'] = $alertRulesDefault; } else { $newGroupName = $groupName; $resp = MonitisApi::addContactGroup(1, $newGroupName); if ($resp['status'] == 'ok') { MonitisConf::$settings['groups'][$mType]['groupId'] = $resp['data']; MonitisConf::$settings['groups'][$mType]['groupName'] = $newGroupName; MonitisConf::$settings['groups'][$mType]['alert'] = $alertRulesDefault; } else { // error return array('status' => 'error', 'msg' => 'Add contact group error ' . $resp['error']); } } // $r = $this->addContacts(ucfirst($mType), MonitisConf::$settings['groups'][$mType]['groupId']); } MonitisConf::update_settings(json_encode(MonitisConf::$settings)); return array('status' => 'ok', 'msg' => 'External, internal groups sets success'); }
function monitis_addon_config() { $configarray = array("name" => "Monitis monitoring", "description" => "Monitis addon for monitoring automation for you and your clients. www.monitis.com", "version" => "1.0", "author" => "Monitis", "logo" => '../modules/addons/monitis_addon/static/img/logo-big.png', "language" => "english", "fields" => array("adminuser" => array("FriendlyName" => "WHMCS Admin", "Type" => "text", "Size" => "25", "Description" => "Username or ID of the admin user under which to execute the WHMCS API call", "Default" => ""))); if (isset($_REQUEST) && isset($_REQUEST['action']) && $_REQUEST['action'] == 'save') { //&& isset($_REQUEST['msave_monitis_addon']) && $_REQUEST['msave_monitis_addon'] == 'Save Changes') { $adminuser = $_REQUEST['fields']['monitis_addon']['adminuser']; MonitisConf::$adminName = MonitisHelper::checkAdminName(); $update = array('admin_name' => MonitisConf::$adminName); $where = array('client_id' => MONITIS_CLIENT_ID); update_query('mod_monitis_setting', $update, $where); } return $configarray; }
public function synchronizeClients() { $all = array(); $subUsers = MonitisApi::clients(true); $clntByUsr = monitisSqlHelper::query('SELECT user_id, firstname, lastname, email, LOWER(status) as status, api_key, secret_key FROM mod_monitis_user LEFT JOIN tblclients ON tblclients.id=mod_monitis_user.user_id'); for ($i = 0; $i < count($subUsers); $i++) { $apikey = $subUsers[$i]['apikey']; $whmcsUser = MonitisHelper::in_array($clntByUsr, 'api_key', $apikey); $userid = 0; // user linked if ($whmcsUser) { $userid = $whmcsUser['user_id']; } else { // link user $arr = explode('_', $subUsers[$i]['account']); if ($arr && $arr[0]) { $userid = intval(substr($arr[0], 5)); if ($userid > 0) { $resp = monitisClientApi::linkUserByApikey($apikey, $userid); if (@$resp['status'] == 'ok' && isset($resp['data'])) { //$secretkey = $resp['data']['secret_key']; $whmcsUser = $this->userById($userid); $whmcsUser['api_key'] = $apikey; $whmcsUser['secret_key'] = $resp['data']['secret_key']; } } } } $monitors = null; if ($userid > 0) { $monitors = $subUsers[$i]['monitors']; $monitors = $this->synchronizeMonitors($userid, $monitors); } $all[] = array('api_user' => $subUsers[$i], 'whmcs_user' => $whmcsUser, 'monitors' => $monitors); } return $all; }
<?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);
static function update_parentDomain() { if (self::$settings && isset(self::$settings['parentDomain']) && !empty(self::$settings['parentDomain'])) { self::$parentDomain = self::$settings['parentDomain']; } else { self::$parentDomain = MonitisHelper::parentDomain(); self::$settings["parentDomain"] = self::$parentDomain; self::update_settings(json_encode(self::$settings)); } }
private function getServerMonitors($server_id, &$arr) { $monitors = array(); for ($i = 0; $i < count($arr); $i++) { if ($arr[$i]["server_id"] == $server_id && MonitisHelper::in_array($this->pubKeys, 'key', $arr[$i]["publickey"])) { $monitors[] = $arr[$i]; } } return $monitors; }
echo "<section>"; //$monitors = $monitors['monitors']; for ($i = 0; $i < count($monitors); $i++) { $monitor = $monitors[$i]; $monitor_id = $monitor['monitor_id']; $monitor_type = $monitor['monitor_type']; $item = $monitor['info']; $sets = $monitor["settings"]; $sets = json_decode($sets, true); //$locationIds = explode(',', $item['locationIds']); $locationIds = explode(',', $item['locations']); $settingProduct = array('interval' => $interval, 'timeout' => $item['timeout'], 'name' => $monitor['info']['name'], 'types' => $monitor_type, 'locationIds' => $locationIds, 'locationsMax' => $sets['locationsMax']); $settingProduct = json_encode($settingProduct); $settingProduct = str_replace('"', "~", $settingProduct); /* notification rule by monitor id */ $alert = MonitisHelper::in_array($alerts, 'monitorId', $monitor_id); $alertAction = 'add_rule'; $rule = $alertAll; $ruleid = $allRuleid; $contactId = $allContactId; if ($alert) { $alertAction = 'edit_rule'; $rule = str_replace('"', "~", $alert['rule']); $ruleid = $alert['id']; $contactId = $alert['contactId']; } /* suspend */ $suspend = 'unsuspend'; if (!$item["isSuspended"]) { $suspend = 'suspend'; }
<th>Status</th> </tr> </thead> <tbody> <?php if (is_array($monitors) && count($monitors)) { $addonUrl = MonitisHelper::adminAddonUrl(); foreach ($monitors as $monitor) { ?> <tr> <!-- td><?php echo $monitor["orderid"]; ?> </td --> <td><a href="<?php echo MonitisHelper::adminOrderUrl($monitor["orderid"]); ?> " target="_blank"><?php echo $monitor["orderid"]; ?> </a></td> <td><?php echo $monitor["ordernum"]; ?> </td> <td><?php echo $monitor["username"]; ?> </td> <td><?php echo $monitor["monitor_type"];
public function createAddonsMonitorByProduct($product) { $result = array('status' => 'ok', 'title' => 'Service: ' . $product['serviceid'] . '/' . $product['addonserviceid'], 'hook_type' => 'multiple', 'multi_type' => 'addon', 'name' => $product['name'], 'username' => $product['username'], 'service_url' => MonitisHelper::adminServicerUrl($product['userid'], $product['serviceid']), 'order_url' => MonitisHelper::adminOrderUrl($product["orderid"])); $response = array('status' => 'error', 'monitor_type' => $product['monitor_type']); if ($product['domainstatus'] == 'Active' && $product['status'] == 'Active') { $response = MonitisSeviceHelper::createMonitor($product); } elseif ($product['domainstatus'] != 'Active' || $product['status'] != 'Active') { $response['msg'] = 'Service: ' . $product['domainstatus'] . '; Addon: ' . $product['status']; } $result['data'] = array(array('product' => $product, 'response' => $response)); if ($response['status'] == 'error') { MonitisHookClass::keepRespose($result, null); } return $result; }
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 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(); } }
function monitisLog($str, $title = '') { if (MONITIS_LOG_ALLOW) { MonitisHelper::log($str, $title); } }
<thead> <tr> <th>Order ID</th> <th>Order #</th> <th>Service</th> <th>Client</th> <th>Monitor Type</th> <th>Domain</th> <th>Dedicated IP</th> <th>Status</th> </tr> </thead> <?php if ($result && count($result) > 0) { $addonUrl = MonitisHelper::adminAddonUrl(); for ($i = 0; $i < count($result); $i++) { $msg = ''; $color = '#000000'; $item = $result[$i]; $product = $item['data'][0]['product']; $response = $item['data'][0]['response']; $orderUrl = $item["order_url"]; $serviceUrl = $item["service_url"]; $isError = false; if ($response["status"] == 'ok') { $color = '#468847'; } elseif ($response["status"] == 'error') { $color = '#cc0000'; $isError = true; } else {
private function initServer(&$server) { $monitor = null; if ($this->allPings) { // define ping monitor by IP $ping = MonitisHelper::in_array($this->allPings, 'url', $server['ipaddress']); if ($ping) { $monitorId = $ping['id']; $linkedMon = MonitisHelper::in_array($this->whmcsExt, 'monitor_id', $monitorId); if (!$linkedMon) { // link ping monitor $linkedMon = monitisSnapShots::linkPingMonitor($monitorId, 'ping', $server['id']); } $monitor = $ping; $monitor['available'] = $linkedMon['available']; $monitor['publickey'] = $linkedMon['publickey']; } } $server['ping'] = $monitor; $agent = $this->agentFullInfo; if ($agent) { $info = $this->intMonitor($agent, $server['id']); $server['agent'] = $info; } return $server; }
public function associateDrives($whmcsDrives, $agentInfo, $serverID) { $result = array("status" => "warning", "msg" => "No agent or agent is stopped"); if ($agentInfo && isset($agentInfo['drives'])) { $agentId = $agentInfo['agentId']; $monDrives = $agentInfo['drives']; $whmcs_drives = null; if ($whmcsDrives) { $whmcs_drives = array(); for ($i = 0; $i < count($whmcsDrives); $i++) { $mon = MonitisHelper::in_array($monDrives, 'id', $whmcsDrives[$i]['monitor_id']); if ($mon) { $whmcs_drives[] = $whmcsDrives[$i]; } else { monitisSqlHelper::altQuery('DELETE FROM ' . MONITIS_INTERNAL_TABLE . ' WHERE monitor_id=' . $whmcsDrives[$i]['monitor_id']); } } } $ids = array(); for ($i = 0; $i < count($monDrives); $i++) { $drive = $monDrives[$i]; if (isset($drive['id'])) { if (!$whmcs_drives || !MonitisHelper::in_array($whmcs_drives, 'monitor_id', $drive['id'])) { $ids[] = $drive['id']; } } } $cnt = count($ids); if ($ids && $cnt > 0) { for ($i = 0; $i < $cnt; $i++) { $monitorID = $ids[$i]; $pubKey = MonitisApi::monitorPublicKey(array('moduleType' => 'drive', 'monitorId' => $monitorID)); $values = array('server_id' => $serverID, 'available' => MonitisConf::$settings['drive']['available'], 'agent_id' => $agentId, 'monitor_id' => $monitorID, 'monitor_type' => 'drive', 'client_id' => MONITIS_CLIENT_ID, "publickey" => $pubKey); insert_query('mod_monitis_int_monitors', $values); } $result["status"] = 'ok'; $result["msg"] = 'Add ' . $cnt . ' drive(s)'; } else { $result["status"] = 'warning'; $result["msg"] = 'No drive monitor for add'; } } return $result; }
public function activateProducts($productIds) { $result = array('status' => 'error', 'products' => array()); $products = $this->allProducts(); if ($products) { $result['status'] = 'ok'; for ($i = 0; $i < count($productIds); $i++) { $prdct = MonitisHelper::in_array($products, 'pid', $productIds[$i]); $productId = intval($productIds[$i]); if ($prdct) { if (isset($prdct['monitisProduct'])) { // monitis product is active if ($prdct['monitisProduct']['settings']) { $result['products'][] = array('status' => 'warning', 'msg' => 'Product "' . $prdct['name'] . '" already has activated'); } else { // activate $setting = MonitisConf::$settings['ping']; $setting['timeoutPing'] = 1000; $setting['timeout'] = 10; $this->activateProduct($productId, json_encode($setting)); $result['products'][] = array('status' => 'ok', 'msg' => 'Product "' . $prdct['name'] . '" activated'); } } else { // set up as monitoring product $this->websiteValue['relid'] = $productId; insert_query('tblcustomfields', $this->websiteValue); $this->monitorTypesValue['relid'] = $productId; insert_query('tblcustomfields', $this->monitorTypesValue); $setting = MonitisConf::$settings['ping']; $setting['timeoutPing'] = 1000; $setting['timeout'] = 10; $this->activateProduct($productId, json_encode($setting)); $result['products'][] = array('status' => 'ok', 'msg' => 'Product "' . $prdct['name'] . '" was set up as monitoring product successful'); } } else { $result['products'][] = array('status' => 'error', 'msg' => 'Error product ' . $productId); } } } return $result; }
public function planDetails($sss) { $result = array('clients' => 0, 'clientsMonitors' => 0, 'uptimeMonitors' => 0, 'locations' => 0, 'agents' => 0); /* * parent user info, plan */ $params = array('loadUserPlan' => 'true'); $userInfo = MonitisApi::userInfo($params); if (isset($userInfo['status']) && $userInfo['status'] == 'error' && isset($userInfo['code']) && $userInfo['code'] == 101) { return null; } $plan = array('roleName' => '', 'uptimePlan' => 0, 'intMonitors' => 0); if ($userInfo) { $roleName = $userInfo['plan']['roleName']; $basketItems = $userInfo['plan']['basketItems']; $plan['roleName'] = $roleName; if (strtoupper($roleName) == 'TRIAL') { $trial = MonitisHelper::in_array($basketItems, 'name', $roleName); if ($trial) { $ext = MonitisHelper::in_array($trial['permissions'], 'actionId', $this->plans["uptimes"]["id"]); // External monitoring / Uptime $plan['uptimePlan'] = $ext['value']; $int = MonitisHelper::in_array($trial['permissions'], 'actionId', $this->plans["servers"]["id"]); // Server $plan['serverPlan'] = $int['value']; } } else { $ext = $this->basketItemById($basketItems, $this->plans["uptimes"]["id"]); $plan['uptimePlan'] = $ext['quantity']; $int = $this->basketItemById($basketItems, $this->plans["servers"]["id"]); $plan['serverPlan'] = $int['quantity']; } $result['plan'] = $plan; } /* * clients info */ $params = array('loadUserPlan' => 'true', 'loadMonitors' => 'true'); $subUsers = MonitisApi::clientsList($params); $userMonitors = 0; for ($i = 0; $i < count($subUsers); $i++) { $userMonitors += count($subUsers[$i]['monitors']); } $result['clients'] = 0; if ($subUsers && count($subUsers) > 0) { $result['clients'] = count($subUsers); } $result['clientsMonitors'] = $userMonitors; /* * parent info * get all uptime monitors */ $snapshots = MonitisApi::externalSnapshot(); $result['uptimeMonitors'] = 0; if ($snapshots && count($snapshots) > 0) { $result['uptimeMonitors'] = count($snapshots); } /* * Server / Device monitors * */ $agentsSnapshot = MonitisApi::allAgentsSnapshot('', true); if ($agentsSnapshot && isset($agentsSnapshot['agents'])) { $result['agents'] = count($agentsSnapshot['agents']); } $result['internalMonitors'] = 0; $internalMonitors = MonitisApi::getInternalMonitors(); if ($internalMonitors) { if (isset($internalMonitors['cpus'])) { $result['internalMonitors'] += count($internalMonitors['cpus']); } if (isset($internalMonitors['memories'])) { $result['internalMonitors'] += count($internalMonitors['memories']); } if (isset($internalMonitors['drives'])) { $result['internalMonitors'] += count($internalMonitors['drives']); } } return $result; }