Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- */
- <?php
- define('OK', 0);
- define('WARNING', 1);
- define('CRITICAL', 2);
- define('UNKNOWN', 3);
- define('DEBUG', false);
- $wArgL = array(
- $warg1 = '30',
- $warg5 = '25',
- $warg15 = '20'
- );
- $cArgL = array(
- $carg1 = '15',
- $carg5 = '10',
- $carg15 = '5'
- );
- $wArgD = '';
- $cArgD = '';
- $ConArg = array(
- $host = '127.0.0.1',
- $port = '22',
- $user = 'root',
- $pass = 'nagiosxi'
- );
- $mode = array(
- 'cpuload',
- 'diskcheck'
- );
- $path = '/';
- $diskMode = array(
- 'USpercent', //Used Space Percentage
- 'FSpercent', // Free Space Percentage
- 'kB',
- 'MB',
- 'KB',
- 'GB',
- 'TB'
- );
- function Connect($ConArg)
- {
- CheckIfEmpty($ConArg)
- $connection = ssh2_connect($host, $port);
- ssh2_auth_password($connection, $user, $pass);
- return($connection);
- }
- function NagOut($msg = '', $exitcode = 0)
- {
- print($msg);
- exit($exitcode);
- }
- function ErrorMsg($errMsg = '', $exitcode = 3)
- {
- print($errMsg);
- exit($exitcode);
- }
- function CheckIfEmpty($someArg)
- {
- $argType = gettype($someArg);
- if($argType == "array")
- {
- $someNum = array_count_values($someArg);
- for($Z = 0, $Z < $someNum, $Z++)
- {
- if(empty($someArg[$Z]) == True)
- {
- ErrorMsg('Some of the crucial array elements are not defined, please check the arguments /n');
- }
- }
- elseif(empty($someArg) == True)
- {
- ErrorMsg('Some of the crucial elements are not defined, please check arguments /n');
- }
- }
- }
- function ArrayComparison($L, $W, $C)
- {
- CheckIfEmpty($W);
- CheckIfEmpty($C);
- for($x = 0, $x <= 2, $x++)
- {
- if($L[$x] > $W[$x] && $L[$x] < $C[$x])
- {
- $status = 1;
- }
- elseif($L[$x] > $C[$x])
- {
- $status = 2;
- }
- else
- {
- $status = 0;
- }
- }
- return($status);
- }
- function CPULoad()
- {
- global $wArgL, $cArgL;
- Connect($ConArg);
- $load = sys_getloadavg();
- CheckIfEmpty($wArgL);
- CheckIfEmpty($cArgL);
- ArrayComparison($load, $wArgL, $cArgL);
- NagOut('CPU Load: '.$load, $status);
- }
- function DiskCheck()
- {
- global $path, $diskMode, $wArgD, $cArgD;
- CheckIfEmpty($diskMode);
- CheckIfEmpty($path);
- CheckIfEmpty($wArgD);
- CheckIfEmpty($cArgD);
- Connect();
- $dfs = disk_free_space($path);
- $dts = disk_total_space($path);
- if($fs >= $wArgD && $fs < $cArgD)
- {
- $statusD = 1;
- }
- elseif($fs >= $cArgD)
- {
- $statusD = 2;
- }
- else
- {
- $statusD = 0;
- }
- switch($diskMode)
- {
- case 'USpercent':
- NagOut('Used Space[%]: '.(100-($dfs/$dts)*100) , $statusD);
- break;
- case 'FSpercent':
- NagOut('Free Space[%]: '.(($dfs/$dts)*100) , $statusD);
- break;
- case 'kB':
- NagOut(/'Total Space[kB]: '.($dts * 1024) 'Free Space[kB]: '/.($dfs * 1024), $statusD);
- break;
- case 'MB':
- NagOut(/'Total Space[MB]: '.($dts * 1024 * 1024) 'Free Space[MB]: '/.($dfs * 1024 * 1024), $statusD);
- break;
- case 'GB':
- NagOut(/'Total Space[GB]: '.($dts * 1024 * 1024 * 1024) 'Free Space[GB]: '/.($dfs * 1024 * 1024 * 1024), $statusD);
- break;
- case 'TB':
- NagOut(/'Total Space[TB]: '.($dts * 1024 * 1024 * 1024 * 1024) 'Free Space[TB]: '/.($dfs * 1024 * 1024 * 1024 * 1024), $statusD);
- default:
- NagOut(/'Total Space[MB]: '.($dts * 1024 * 1024) 'Free Space[MB]: '/.($dfs * 1024 * 1024), $statusD);
- }
- }
- function ModeSelect()
- {
- global $mode;
- switch($mode)
- {
- case 'cpuload':
- CPULoad();
- break;
- case 'diskcheck':
- DiskCheck();
- break;
- default:
- DiskCheck();
- }
- }
- function Main()
- {
- ModeSelect();
- }
- Main();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement