<commit_before><?php
define('NAGIOS_CODE_OK', 0);
define('NAGIOS_CODE_WARNING', 1);
define('NAGIOS_CODE_CRITICAL', 2);
define('NAGIOS_CODE_UNKNOWN', 3);


$kalturaRootPath = realpath(__DIR__ . '/../../../');

require_once "$kalturaRootPath/tests/monitoring/KalturaMonitorResult.php";
if($argc == 1)
{
	echo "usage...";
}

$systemConfig = parse_ini_file("$kalturaRootPath/configurations/system.template.ini");

$options = getopt("e:w:");

$errorThreshold = $options["e"];
$warningThreshold = $options["w"];

$testScript = $argv[1];
$testScriptCmd = implode(" ", array_slice($argv, 1));
$testScriptCmd = substr($testScriptCmd, 2);

$outputLines = null;
$returnedValue = null;
$output = exec($systemConfig['PHP_BIN'] . ' ' . $testScriptCmd, $outputLines, $returnedValue);
if($returnedValue !== 0)
{
	echo $output;
	exit(NAGIOS_CODE_UNKNOWN);
}

$xml = implode("\n", $outputLines);
$monitorResult = KalturaMonitorResult::fromXml($xml);

if($monitorResult->errors)
{
	$strErr = '';
	foreach($monitorResult->errors as $error)
	{
		$strErr .= $error->description;
	}
	echo $strErr;
	exit(NAGIOS_CODE_UNKNOWN);
}

if(isset($errorThreshold) && $monitorResult->value > $errorThreshold)
{
	echo 'ERROR -  monitor value: ' . $monitorResult->value . ' exceeded error value: ' . $errorThreshold;
	exit(NAGIOS_CODE_CRITICAL);
}
<commit_msg>qnd: check options are set before using them<commit_after><?php
define('NAGIOS_CODE_OK', 0);
define('NAGIOS_CODE_WARNING', 1);
define('NAGIOS_CODE_CRITICAL', 2);
define('NAGIOS_CODE_UNKNOWN', 3);


$kalturaRootPath = realpath(__DIR__ . '/../../../');

require_once "$kalturaRootPath/tests/monitoring/KalturaMonitorResult.php";
if($argc == 1)
{
	echo "usage...";
}

$systemConfig = parse_ini_file("$kalturaRootPath/configurations/system.template.ini");

$errorThreshold = null;
$warningThreshold = null;

$options = getopt('e:w:');
if(isset($options['e']))
	$errorThreshold = $options['e'];
if(isset($options['w']))
	$warningThreshold = $options['w'];

$testScriptCmd = implode(' ', array_slice($argv, 1));
$testScriptCmd = substr($testScriptCmd, 2);

$outputLines = null;
$returnedValue = null;
$output = exec($systemConfig['PHP_BIN'] . ' ' . $testScriptCmd, $outputLines, $returnedValue);
if($returnedValue !== 0)
{
	echo $output;
	exit(NAGIOS_CODE_UNKNOWN);
}

$xml = implode("\n", $outputLines);
$monitorResult = KalturaMonitorResult::fromXml($xml);

if($monitorResult->errors)
{
	$strErr = '';
	foreach($monitorResult->errors as $error)
	{
		$strErr .= $error->description;
	}
	echo $strErr;
	exit(NAGIOS_CODE_UNKNOWN);
}

if(isset($errorThreshold) && $monitorResult->value > $errorThreshold)
{
	echo 'ERROR -  monitor value: ' . $monitorResult->value . ' exceeded error value: ' . $errorThreshold;
	exit(NAGIOS_CODE_CRITICAL);
}

{'fraction_non_alphanumeric': 0.1881116346502356, 'fraction_numerical': 0.0061616527727437476, 'mean_word_length': 6.36, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5263258', 'n_tokens_mistral': 1018, 'n_tokens_neox': 991, 'n_words': 163}