Exemple #1
0
 static function parentDomain()
 {
     $resp = MonitisApi::userInfo(array("apikey" => MonitisConf::$apiKey));
     if (isset($resp['account'])) {
         $userDomain = explode('@', $resp['account']);
         return $userDomain[1];
     } else {
         return 'monitis.ccom';
     }
 }
Exemple #2
0
function monitis_embed_internalSnapshot($monitor_type, $ids)
{
    $params = array('moduleType' => $monitor_type);
    $resp = MonitisApi::getWidget($params);
    if ($resp && isset($resp['data'])) {
        return '<script type="text/javascript">
monitis_embed_module_id="' . $resp['data'] . '";
monitis_embed_module_width="500";
monitis_embed_module_height="350";
monitis_embed_module_readonly="false";
monitis_embed_module_monitorIds="' . $ids . '"; /*filter results by testIds*/
</script>
<script type="text/javascript" src="' . MONITISAPIURL_JS . '/sharedModule/shareModule.js"></script>
<noscript><a href="http://monitis.com">Monitoring by Monitis. Please enable JavaScript to see the report!</a> </noscript>';
    } else {
        return '<div style="width:500px;text-align:center">No data to display</div>';
    }
}
Exemple #3
0
    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;
    }
 public function getGroupIdsByContcatId($contactId)
 {
     $idList = $this->getGruopIdList();
     $allGroups = MonitisApi::getContactsByGroupID(implode(",", $idList));
     $array = array();
     for ($i = 0; $i < count($allGroups); $i++) {
         foreach ($allGroups[$i]['contacts'] as $contact) {
             if ($contact['contactId'] == $contactId) {
                 $array[] = $allGroups[$i]['contactGroupId'];
             }
         }
     }
     return $array;
 }
Exemple #5
0
 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;
 }
Exemple #6
0
 static function update_token()
 {
     $authToken = MonitisApi::getAuthToken();
     if ($authToken) {
         self::$authToken = $authToken;
         $update = array('authToken' => $authToken, 'authToken_update' => date("Y-m-d H:i:s", time()));
         $where = array('client_id' => MONITIS_CLIENT_ID);
         update_query(MONITIS_SETTING_TABLE, $update, $where);
         return true;
     } else {
         //echo '<div><b> Monitis server not respose!</b></div>';
         return false;
     }
 }
Exemple #7
0
 public function userNetworkStatus($userid)
 {
     $result = array();
     if ($userid > 0) {
         $srvrs = $this->client_serversIds($userid);
         if ($srvrs && $srvrs["status"] == 'ok' && count($srvrs["data"]) > 0) {
             $all_srvrs = $srvrs["data"];
             $serdersIds = $this->_idsList($all_srvrs, 'serverid');
             //$serdersIds = array_unique($serdersIds);
             $srvrsIds = implode(',', $serdersIds);
             $ext = $this->servers_ext($srvrsIds, 1);
             // 1 - availble
             $int = $this->servers_int($srvrsIds, 1);
             if ($ext && count($ext) > 0 || $int && count($int) > 0) {
                 $this->pubKeys = MonitisApi::getPublicKeys();
                 for ($s = 0; $s < count($all_srvrs); $s++) {
                     $serverid = $all_srvrs[$s]['serverid'];
                     if ($ext && count($ext) > 0) {
                         $extMon = $this->getServerMonitors($serverid, $ext);
                         $all_srvrs[$s]['external'] = $extMon;
                     }
                     if ($int && count($int) > 0) {
                         $intMon = $this->getServerMonitors($serverid, $int);
                         $all_srvrs[$s]['internal'] = $intMon;
                     }
                 }
                 $result["status"] = 'ok';
                 $result["data"] = $all_srvrs;
             } else {
                 $result["status"] = 'error';
                 $result["msg"] = 'No monitors for the active products, or they are not available';
             }
         } else {
             $result["status"] = 'error';
             $result["msg"] = $srvrs["msg"];
         }
     } else {
         $result["status"] = 'error';
         $result["msg"] = 'User login error';
     }
     return $result;
 }
Exemple #8
0
            $monitisContactGroup = MonitisApi::getContactsByGroupID($groupId);
            if (is_array($monitisContactGroup)) {
                foreach ($monitisContactGroup[0]['contacts'] as $contact) {
                    $notificationRuleIdsOnContact = $notifications->getNotifRuleIds($contact['contactId'], $groupType);
                    if ($notificationRuleIdsOnContact != '') {
                        $notifications->editNotificationRule($contact['contactId'], $groupName, $groupAlerts, $notificationRuleIdsOnContact);
                    } else {
                        MonitisApiHelper::addNotificationRule($contact['contactId'], $groupType, $groupId, $groupAlerts);
                    }
                }
            }
            break;
    }
}
MonitisApp::printNotifications();
$monitisContactGroups = MonitisApi::getContactsByGroupID('All');
if (!$monitisContactGroups) {
    $monitisContactGroups = $notifications->createDefaultGroup();
}
$whmcsAdmins = monitisSqlHelper::query('SELECT CONCAT(firstname, " ", lastname) as name, email FROM tbladmins');
$contactGroups = array();
for ($i = 0; $i < count($monitisContactGroups); $i++) {
    $contactGroups[$i] = array();
    $contactGroups[$i]['id'] = $monitisContactGroups[$i]['contactGroupId'];
    $contactGroups[$i]['name'] = $monitisContactGroups[$i]['contactGroupName'];
    $alertRules = '';
    if (MonitisConf::$settings['groups']['external']['groupId'] == $monitisContactGroups[$i]['contactGroupId']) {
        $monitorType = 'external';
        $externalAlerts = MonitisApiHelper::getNotificationRuleByType($monitorType, $monitisContactGroups[$i]['contactGroupId']);
        if ($externalAlerts) {
            $alertRules = json_encode($externalAlerts);
 static function getUserByEmail($user)
 {
     $allUsers = MonitisApi::clients();
     for ($i = 0; $i < count($allUsers); $i++) {
         if (strtolower($allUsers[$i]['account']) == strtolower($user['email'])) {
             return $allUsers[$i];
         }
     }
     return null;
 }
Exemple #10
0
 public function getMonitor($monitorId, $type)
 {
     $resp = null;
     if ($monitorId && $monitorId > 0) {
         if ($type == 'cpu') {
             $resp = MonitisApi::getCPUMonitor($monitorId);
             $resp = $this->whmcsInfo($resp, $monitorId, 'internal');
         } elseif ($type == 'memory') {
             $resp = MonitisApi::getMemoryInfo($monitorId);
             $resp = $this->whmcsInfo($resp, $monitorId, 'internal');
         } elseif ($type == 'drive') {
             $resp = MonitisApi::getDriveInfo($monitorId);
             $resp = $this->whmcsInfo($resp, $monitorId, 'internal');
         } elseif ($type == 'ping' || $type == 'external') {
             $ping = MonitisApi::getExternalMonitorInfo($monitorId);
             $locs = array();
             $intervals = array();
             for ($i = 0; $i < count($ping['locations']); $i++) {
                 $locs[] = $ping['locations'][$i]['id'];
                 $intervals[] = $ping['locations'][$i]['checkInterval'];
             }
             $ping['locations'] = implode(',', $locs);
             $ping['intervals'] = implode(',', $intervals);
             $ping['id'] = $monitorId;
             $resp = $this->whmcsInfo($ping, $monitorId, 'external');
         }
     }
     return $resp;
 }
Exemple #11
0
<?php

$isNewAcc = empty(MonitisConf::$apiKey);
if (monitisPostInt('monitisFormSubmitted')) {
    $apiKey = trim(monitisPost('apiKey'));
    $secretKey = trim(monitisPost('secretKey'));
    $timezone = monitisPostInt('monitisTimeZone');
    if (empty($apiKey)) {
        MonitisApp::addError('Please provide valid API Key');
    } elseif (empty($secretKey)) {
        MonitisApp::addError('Please provide valid Secret Key');
    } elseif (!MonitisApi::checkKeysValid($apiKey, $secretKey)) {
        MonitisApp::addError('Wrong API and/or Secret keys provided.');
    } else {
        MonitisConf::update_config(array('apiKey' => $apiKey, 'secretKey' => $secretKey, 'timezone' => $timezone));
        if ($isNewAcc) {
            //header('location: ' . MONITIS_APP_URL . '&monitis_page=configure&isNewAcc=1');
            header('location: ' . MONITIS_APP_URL . '&monitis_page=tabadmin&sub=settings&isNewAcc=1');
        }
    }
} else {
    if ($isNewAcc) {
        MonitisApp::addMessage('Please enter your Monitis account information below.');
    }
}
MonitisApp::printNotifications();
?>
<script type="text/javascript">
$(document).ready(function() {
	var d = new Date();
	var minutes = d.getTimezoneOffset(); // minutes
Exemple #12
0
					UPDATE `mod_monitis_options`
					SET is_active = "' . $isActive . '"
					WHERE option_id = ' . $subId . '
				';
                mysql_query($query);
            }
            /* if ($isActive && $subIds) {
            				$success = 'Option have been activated.';
            			} elseif ($subIds != null) {
            				$success = 'Option have been deactivated.';
            			} */
            break;
    }
}
$locations = MonitisConf::$locations;
$contactGroups = MonitisApi::getContactGroupList();
$query = '
	SELECT groups.id AS group_id, groups.name AS group_name, options.id AS option_id, options.optionname AS option_name,
		subs.id AS sub_id, subs.optionname AS sub_name, moptions.option_id as oid,
		moptions.type, moptions.settings, moptions.is_active
	FROM `mod_monitis_options` AS moptions
		JOIN `tblproductconfigoptionssub` AS subs
			ON subs.id = moptions.option_id
		LEFT JOIN `tblproductconfigoptions` AS options
			ON options.id = subs.configid
		LEFT JOIN `tblproductconfiggroups` AS groups
			ON groups.id = options.gid
';
$result = mysql_query($query);
$groups = array();
$subsCount = 0;
Exemple #13
0
 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();
     }
 }
Exemple #14
0
                        for ($i = 0; $i < count($serverInfo['agent']['drive']); $i++) {
                            if (isset($serverInfo['agent']['drive'][$i]['letter']) && $serverInfo['agent']['drive'][$i]['letter'] === $driveLetter) {
                                $serverInfo['agent']['drive'][$i] = $serverMonitors->getMonitor($monitorId, 'drive');
                            }
                        }
                    } else {
                        MonitisApp::addError($resp['error']);
                    }
                }
            } else {
                $params = array('agentkey' => $agentKey, 'driveLetter' => $driveLetter, 'freeLimit' => $freeLimit, 'name' => 'drive_' . $driveLetter . '@' . $serverInfo['hostname'], 'tag' => $serverInfo['hostname'] . '_whmcs');
                $resp = MonitisApi::addDriveMonitor($params);
                if ($resp) {
                    if ($resp['status'] == 'ok') {
                        $newID = $resp['data']['testId'];
                        $pubKey = MonitisApi::monitorPublicKey(array('moduleType' => 'drive', 'monitorId' => $newID));
                        $values = array('server_id' => $serverInfo['id'], 'available' => MonitisConf::$settings['drive']['available'], 'agent_id' => $agentId, 'monitor_id' => $newID, 'monitor_type' => 'drive', 'client_id' => MONITIS_CLIENT_ID, 'publickey' => $pubKey);
                        insert_query('mod_monitis_int_monitors', $values);
                        MonitisApp::addMessage('Drive Monitor successfully added');
                        for ($i = 0; $i < count($serverInfo['agent']['drive']); $i++) {
                            if (isset($serverInfo['agent']['drive'][$i]['driveLetter']) && $serverInfo['agent']['drive'][$i]['driveLetter'] === $driveLetter) {
                                $serverInfo['agent']['drive'][$i] = $serverMonitors->getMonitor($resp['data']['testId'], 'drive');
                            }
                        }
                    } else {
                        MonitisApp::addError($resp['error']);
                    }
                }
            }
    }
}
Exemple #15
0
 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;
 }
 static function alertGroupById($alertGroupId, &$groupList)
 {
     $max_len = 20;
     $grouptitle = $groupname = 'no alert';
     if ($alertGroupId > 0) {
         if (!isset($groupList) || !$groupList) {
             $groupList = MonitisApi::getContactGroupList();
         }
         $groupname = self::groupNameByGroupId($alertGroupId, $groupList);
         $grouptitle = strlen($groupname) > $max_len ? substr($groupname, 0, $max_len) . '...' : $groupname;
     }
     return array('id' => $alertGroupId, 'name' => $groupname, 'title' => $grouptitle);
 }