// | the Free Software Foundation; either version 3 of the License, or | // | (at your option) any later version. | // | | // | This program is distributed in the hope that it will be useful, | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // | | // +----------------------------------------------------------------------+ // Change this accordingly $statusFile = "/opt/local/var/nagios/status.dat"; $nag_version = getFileVersion($statusFile); $created_ts = 0; $debug = false; if ($nag_version == 4) { $data = getData4($statusFile); } else { if ($nag_version == 3) { $data = getData3($statusFile); } else { $data = getData2($statusFile); } } $hosts = $data['hosts']; $services = $data['services']; $program = ""; if (array_key_exists("program", $data)) { $program = $data['program']; } outputJson($hosts, $services, $program); function outputJson($hosts, $services, $program)
function getActivityData($a_params) { //indicates number of activity indicator, now in [0..5] $indicatorNr = $a_params['indicatorNr']; //indicates number for sub activity indicator, possible value depends on value of indicatorNr $subIndicatorNr = $a_params['subIndicatorNr']; $f_params = array(); //indicates for what other users data is visible. 0=mean other, 1=anonymous others, 2=others $f_params['privacyLevel'] = $a_params['privacyLevel']; //0=all groups, so elgg total. If >0 then data is filtered for group guid $f_params['groupGuid'] = $a_params['groupGuid']; //indicates if activity and performance should be shared with other users. 0=no, 1=yes $f_params['shareWithOthers'] = $a_params['shareWithOthers']; //indicates if activity and performance should always shared. 0=no, 1=yes $f_params['alwaysShowOthers'] = $a_params['alwaysShowOthers']; //comma separated list of user guids that must be excluded from the data //if one of these users is the current user, me should be excluded from the data $f_params['excludedFromDashboardUserGuids'] = $a_params['excludedFromDashboardUserGuids']; //if >0 get all data starting from startEpoch $f_params['startEpoch'] = $a_params['startEpoch']; //if >0 get all data till endEpoch $f_params['endEpoch'] = $a_params['endEpoch']; //get all data in intervals between startEpoch and endEpoch $f_params['numberOfMonths'] = $a_params['numberOfMonths']; //get all data in intervals between startEpoch and endEpoch $f_params['numberOfIntervals'] = $a_params['numberOfIntervals']; //get end date, it is in format yyyy-mm-dd $f_params['endDate'] = $a_params['endDate']; //indicates for which users data should be given. 0=all users, 1=current user, 2=all but current user $f_params['userCollectionNr'] = $a_params['userCollectionNr']; //minimal 1 interval if ($f_params['numberOfIntervals'] == 0) { $f_params['numberOfIntervals'] = 1; } //determine endEpoch if not set if ($f_params['endEpoch'] == 0) { if ($f_params['endDate'] != '') { $f_params['endEpoch'] = strtotime($f_params['endDate']); } else { //set it to now $f_params['endEpoch'] = time(); } } //if numberOfMonths > 0, set endEpoch to end of month so intervals roughly correspond to months if ($f_params['numberOfMonths'] > 0) { $month = date("m", $f_params['endEpoch']); $year = date("Y", $f_params['endEpoch']); $f_params['endEpoch'] = mktime(23, 59, 59, ++$month, 0, $year); } //determine $startEpoch if ($f_params['numberOfMonths'] > 0) { $f_params['startEpoch'] = strtotime("-" . $f_params['numberOfMonths'] . " Months", $f_params['endEpoch']); } else { if ($f_params['startEpoch'] == 0) { //get oldest timestamp in database $sql = " SELECT posted AS time FROM elgg_river ORDER BY posted ASC LIMIT 1"; $f_params['startEpoch'] = getTime($sql); } } $f_params['intervalTime'] = ($f_params['endEpoch'] - $f_params['startEpoch']) / $f_params['numberOfIntervals']; $users = getUsers($f_params); $f_params['users'] = $users; $showUsers = getShowUsers($f_params); $f_params['showUsers'] = $showUsers; $userGuids = getUserGuids($f_params); $f_params['userGuids'] = $userGuids; $userNames = getUserNames($f_params); $f_params['userNames'] = $userNames; // $numberOfCreatedUsers = getNumberOfIntervalUsers($f_params, "create"); // $numberOfBannedUsers = getNumberOfIntervalUsers($f_params, "ban"); $numberOfUsers = getNumberOfUsers($f_params); // $f_params['numberOfCreatedUsers'] = $numberOfCreatedUsers; // $f_params['numberOfBannedUsers'] = $numberOfBannedUsers; $f_params['numberOfUsers'] = $numberOfUsers; $data = ""; if ($indicatorNr == 0 && $subIndicatorNr == -1) { //I am productive $data = getUserResults(getData0($f_params), $f_params); } else { if ($indicatorNr == 1 && $subIndicatorNr == -1) { //I deliver quality contributions $data = getUserResults(getData1($f_params), $f_params); } else { if ($indicatorNr == 2 && $subIndicatorNr == -1) { //I am involved $data = getUserResults(getData2($f_params), $f_params); } else { if ($indicatorNr == 3 && $subIndicatorNr == -1) { //I am socially active $data = getUserResults(getData3($f_params), $f_params); } else { if ($indicatorNr == 4 && $subIndicatorNr == -1) { //I am available $data = getUserResults(getData4($f_params), $f_params); } else { if ($indicatorNr == 5 && $subIndicatorNr == -1) { //I am reading $data = getUserResults(getData5($f_params), $f_params); } else { if ($indicatorNr == 0 && $subIndicatorNr == 0) { //I am productive, number of objects created and updated, by all users, current user or all but current user $data = getResult(getNumberOfCreatedAndUpdatedObjects($f_params)); } else { if ($indicatorNr == 0 && $subIndicatorNr == 1) { //I am involved, number of comments to other users, for all users, current user or all but current user $data = getResult(getNumberOfCommentsToOthers($f_params)); } else { if ($indicatorNr == 1 && $subIndicatorNr == 0) { //I deliver quality contributions, number of ratings from others on created or updated objects and groups, for all users, current user or all but current user $data = getResult(getNumberOfRatingsFromOthers($f_params)); } else { if ($indicatorNr == 1 && $subIndicatorNr == 1) { //I deliver quality contributions, mean rating from others on created or updated objects and groups, for all users, current user or all but current user $data = getResult(getMeanRatingFromOthers($f_params)); } else { if ($indicatorNr == 2 && $subIndicatorNr == 0) { //I am involved, number of ratings to others on created or updated objects and groups, for all users, current user or all but current user $data = getResult(getNumberOfRatingsToOthers($f_params)); } else { if ($indicatorNr == 2 && $subIndicatorNr == 1) { //I am involved, number of comments to other users, for all users, current user or all but current user $data = getResult(getNumberOfCommentsToOthers($f_params)); } else { if ($indicatorNr == 3 && $subIndicatorNr == 0) { //I am socially active, number of friend requests by others, for all users, current user or all but current user $data = getResult(getNumberOfFriendRequestsFromOthers($f_params)); } else { if ($indicatorNr == 3 && $subIndicatorNr == 1) { //I am socially active, number of friend requests to others, for all users, current user or all but current user $data = getResult(getNumberOfFriendRequestsToOthers($f_params)); } else { if ($indicatorNr == 4 && $subIndicatorNr == 0) { //I am available, number of plugin views (also updates), for all users, current user or all but current user $data = getResult(getNumberOfPluginViews($f_params)); } } } } } } } } } } } } } } } $result = ''; if ($indicatorNr >= 0 && $subIndicatorNr >= 0) { $result .= "{"; $result .= "\"userids\": " . getResult($userGuids) . ",\n"; $result .= "\"usernames\": " . getStringResult($userNames) . ",\n"; $result .= "\"showUsers\": " . getResult($showUsers) . ",\n"; $result .= "\"count\": " . $data; $result .= "}"; } else { if ($indicatorNr >= 0 && $subIndicatorNr == -1) { $result .= "{"; $result .= "\"userids\": " . getResult($userGuids) . ",\n"; $result .= "\"usernames\": " . getStringResult($userNames) . ",\n"; $result .= "\"showUsers\": " . getResult($showUsers) . ",\n"; $result .= "\"data\": " . $data; $result .= "}"; } else { $result .= "{"; $result .= "\"userids\": " . getResult($userGuids) . ",\n"; $result .= "\"usernames\": " . getStringResult($userNames) . ",\n"; $result .= "\"showUsers\": " . getResult($showUsers) . ",\n"; $f_params['data0'] = getData0($f_params); $f_params['data1'] = getData1($f_params); $f_params['data2'] = getData2($f_params); $f_params['data3'] = getData3($f_params); $f_params['data4'] = getData4($f_params); $result .= "\"data0\": " . getUserResults($f_params['data0'], $f_params) . ",\n" . "\"data1\": " . getUserResults($f_params['data1'], $f_params) . ",\n" . "\"data2\": " . getUserResults($f_params['data2'], $f_params) . ",\n" . "\"data3\": " . getUserResults($f_params['data3'], $f_params) . ",\n" . "\"data4\": " . getUserResults($f_params['data4'], $f_params); $result .= "}"; } } return $result; }