Merge branch 'bugfix/show-non-piechart-perfdata-not-as-piechart-6515'

fixes #6515
This commit is contained in:
Johannes Meyer 2014-07-14 13:49:04 +02:00
commit a40feeb324
6 changed files with 184 additions and 100 deletions

View File

@ -263,13 +263,13 @@ class ListCommand extends Command
try { try {
$pset = PerfdataSet::fromString($row->service_perfdata); $pset = PerfdataSet::fromString($row->service_perfdata);
$perfs = array(); $perfs = array();
foreach ($pset as $perfName => $p) { foreach ($pset as $p) {
if ($percent = $p->getPercentage()) { if ($percent = $p->getPercentage()) {
if ($percent < 0 || $percent > 100) { if ($percent < 0 || $percent > 100) {
continue; continue;
} }
$perfs[] = ' ' $perfs[] = ' '
. $perfName . $p->getLabel()
. ': ' . ': '
. $this->getPercentageSign($percent) . $this->getPercentageSign($percent)
. ' ' . ' '

View File

@ -11,14 +11,18 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
{ {
public function perfdata($perfdataStr, $compact = false, $float = false) public function perfdata($perfdataStr, $compact = false, $float = false)
{ {
$pset = PerfdataSet::fromString($perfdataStr)->asArray();
$onlyPieChartData = array_filter($pset, function ($e) { return $e->getPercentage() > 0; });
if ($compact) {
$onlyPieChartData = array_slice($onlyPieChartData, 0, 5);
} else {
$nonPieChartData = array_filter($pset, function ($e) { return $e->getPercentage() == 0; });
}
$result = ''; $result = '';
$table = array(); $table = array();
$pset = array_slice(PerfdataSet::fromString($perfdataStr)->asArray(), 0, ($compact ? 5 : null)); foreach ($onlyPieChartData as $perfdata) {
foreach ($pset as $label => $perfdata) { $pieChart = $this->createInlinePie($perfdata);
if (!$perfdata->isPercentage() && $perfdata->getMaximumValue() === null) {
continue;
}
$pieChart = $this->createInlinePie($perfdata, $label, htmlspecialchars($label));
if ($compact) { if ($compact) {
if (! $float) { if (! $float) {
$result .= $pieChart->render(); $result .= $pieChart->render();
@ -27,22 +31,23 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
} }
} else { } else {
if (! $perfdata->isPercentage()) { if (! $perfdata->isPercentage()) {
// TODO: Should we trust sprintf-style placeholders in perfdata titles?
$pieChart->setTooltipFormat('{{label}}: {{formatted}} ({{percent}}%)'); $pieChart->setTooltipFormat('{{label}}: {{formatted}} ({{percent}}%)');
} }
$pieChart->setStyle('margin: 0.2em 0.5em 0.2em 0.5em;'); $pieChart->setStyle('margin: 0.2em 0.5em 0.2em 0.5em;');
$table[] = '<tr><th>' . $pieChart->render() $table[] = '<tr><th>' . $pieChart->render()
. htmlspecialchars($label) . htmlspecialchars($perfdata->getLabel())
. '</th><td> ' . '</th><td> '
. htmlspecialchars($this->formatPerfdataValue($perfdata)) . . htmlspecialchars($this->formatPerfdataValue($perfdata)) .
' </td></tr>'; ' </td></tr>';
} }
} }
// TODO: What if we have both? And should we trust sprintf-style placeholders in perfdata titles? if ($compact) {
if (empty($table)) { return $result;
return $compact ? $result : $perfdataStr;
} else { } else {
return '<table class="perfdata">' . implode("\n", $table) . '</table>'; $pieCharts = empty($table) ? '' : '<table class="perfdata">' . implode("\n", $table) . '</table>';
return $pieCharts . "\n" . implode("<br>\n", $nonPieChartData);
} }
} }
@ -81,10 +86,10 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
return $perfdata->getValue(); return $perfdata->getValue();
} }
protected function createInlinePie(Perfdata $perfdata, $title, $label = '') protected function createInlinePie(Perfdata $perfdata)
{ {
$pieChart = new InlinePie($this->calculatePieChartData($perfdata), $title); $pieChart = new InlinePie($this->calculatePieChartData($perfdata), $perfdata->getLabel());
$pieChart->setLabel($label); $pieChart->setLabel(htmlspecialchars($perfdata->getLabel()));
$pieChart->setHideEmptyLabel(); $pieChart->setHideEmptyLabel();
//$pieChart->setHeight(32)->setWidth(32); //$pieChart->setHeight(32)->setWidth(32);

View File

@ -4,7 +4,7 @@
namespace Icinga\Module\Monitoring\Plugin; namespace Icinga\Module\Monitoring\Plugin;
use Icinga\Exception\ProgrammingError; use InvalidArgumentException;
class Perfdata class Perfdata
{ {
@ -22,6 +22,13 @@ class Perfdata
*/ */
protected $unit; protected $unit;
/**
* The label
*
* @var string
*/
protected $label;
/** /**
* The value * The value
* *
@ -58,13 +65,15 @@ class Perfdata
protected $criticalThreshold; protected $criticalThreshold;
/** /**
* Create a new Perfdata object based on the given performance data value * Create a new Perfdata object based on the given performance data label and value
* *
* @param string $perfdataValue The value to parse * @param string $label The perfdata label
* @param string $value The perfdata value
*/ */
protected function __construct($perfdataValue) public function __construct($label, $value)
{ {
$this->perfdataValue = $perfdataValue; $this->perfdataValue = $value;
$this->label = $label;
$this->parse(); $this->parse();
if ($this->unit === '%') { if ($this->unit === '%') {
@ -78,25 +87,30 @@ class Perfdata
} }
/** /**
* Return a new Perfdata object based on the given performance data value * Return a new Perfdata object based on the given performance data key=value pair
* *
* @param string $perfdataValue The value to parse * @param string $perfdata The key=value pair to parse
* *
* @return Perfdata * @return Perfdata
* *
* @throws ProgrammingError In case the given performance data value has no content * @throws InvalidArgumentException In case the given performance data has no content or a invalid format
*/ */
public static function fromString($perfdataValue) public static function fromString($perfdata)
{ {
if (empty($perfdataValue)) { if (empty($perfdata)) {
throw new ProgrammingError('Perfdata::fromString expects a string with content'); throw new InvalidArgumentException('Perfdata::fromString expects a string with content');
} elseif (false === strpos($perfdata, '=')) {
throw new InvalidArgumentException(
'Perfdata::fromString expects a key=value formatted string. Got "' . $perfdata . '" instead'
);
} }
return new static($perfdataValue); list($label, $value) = explode('=', $perfdata, 2);
return new static(trim($label), trim($value));
} }
/** /**
* Return whether this performance data value is a number * Return whether this performance data's value is a number
* *
* @return bool True in case it's a number, otherwise False * @return bool True in case it's a number, otherwise False
*/ */
@ -106,7 +120,7 @@ class Perfdata
} }
/** /**
* Return whether this performance data value are seconds * Return whether this performance data's value are seconds
* *
* @return bool True in case it's seconds, otherwise False * @return bool True in case it's seconds, otherwise False
*/ */
@ -116,7 +130,7 @@ class Perfdata
} }
/** /**
* Return whether this performance data value is in percentage * Return whether this performance data's value is in percentage
* *
* @return bool True in case it's in percentage, otherwise False * @return bool True in case it's in percentage, otherwise False
*/ */
@ -126,7 +140,7 @@ class Perfdata
} }
/** /**
* Return whether this performance data value is in bytes * Return whether this performance data's value is in bytes
* *
* @return bool True in case it's in bytes, otherwise False * @return bool True in case it's in bytes, otherwise False
*/ */
@ -136,7 +150,7 @@ class Perfdata
} }
/** /**
* Return whether this performance data value is a counter * Return whether this performance data's value is a counter
* *
* @return bool True in case it's a counter, otherwise False * @return bool True in case it's a counter, otherwise False
*/ */
@ -145,6 +159,14 @@ class Perfdata
return $this->unit === 'c'; return $this->unit === 'c';
} }
/**
* Return this perfomance data's label
*/
public function getLabel()
{
return $this->label;
}
/** /**
* Return the value or null if it is unknown (U) * Return the value or null if it is unknown (U)
* *
@ -176,7 +198,7 @@ class Perfdata
} }
/** /**
* Return this value's warning treshold or null if it is not available * Return this performance data's warning treshold or null if it is not available
* *
* @return null|string * @return null|string
*/ */
@ -186,7 +208,7 @@ class Perfdata
} }
/** /**
* Return this value's critical treshold or null if it is not available * Return this performance data's critical treshold or null if it is not available
* *
* @return null|string * @return null|string
*/ */
@ -215,6 +237,16 @@ class Perfdata
return $this->maxValue; return $this->maxValue;
} }
/**
* Return this performance data as string
*
* @return string
*/
public function __toString()
{
return sprintf(strpos($this->label, ' ') === false ? '%s=%s' : "'%s'=%s", $this->label, $this->perfdataValue);
}
/** /**
* Parse the current performance data value * Parse the current performance data value
* *

View File

@ -85,7 +85,7 @@ class PerfdataSet implements IteratorAggregate
$value = trim($this->readUntil(' ')); $value = trim($this->readUntil(' '));
if ($label && $value) { if ($label && $value) {
$this->perfdata[$label] = Perfdata::fromString($value); $this->perfdata[] = new Perfdata($label, $value);
} }
} }
} }

View File

@ -17,19 +17,19 @@ class PerfdataSetTest extends BaseTestCase
public function testWhetherValidSimplePerfdataLabelsAreProperlyParsed() public function testWhetherValidSimplePerfdataLabelsAreProperlyParsed()
{ {
$pset = PerfdataSetWithPublicData::fromString('key1=val1 key2=val2 key3 =val3'); $pset = PerfdataSetWithPublicData::fromString('key1=val1 key2=val2 key3 =val3');
$this->assertArrayHasKey( $this->assertEquals(
'key1', 'key1',
$pset->perfdata, $pset->perfdata[0]->getLabel(),
'PerfdataSet does not correctly parse valid simple labels' 'PerfdataSet does not correctly parse valid simple labels'
); );
$this->assertArrayHasKey( $this->assertEquals(
'key2', 'key2',
$pset->perfdata, $pset->perfdata[1]->getLabel(),
'PerfdataSet does not correctly parse valid simple labels' 'PerfdataSet does not correctly parse valid simple labels'
); );
$this->assertArrayHasKey( $this->assertEquals(
'key3', 'key3',
$pset->perfdata, $pset->perfdata[2]->getLabel(),
'PerfdataSet does not correctly parse valid simple labels' 'PerfdataSet does not correctly parse valid simple labels'
); );
} }
@ -37,14 +37,14 @@ class PerfdataSetTest extends BaseTestCase
public function testWhetherNonQuotedPerfdataLablesWithSpacesAreProperlyParsed() public function testWhetherNonQuotedPerfdataLablesWithSpacesAreProperlyParsed()
{ {
$pset = PerfdataSetWithPublicData::fromString('key 1=val1 key 1 + 1=val2'); $pset = PerfdataSetWithPublicData::fromString('key 1=val1 key 1 + 1=val2');
$this->assertArrayHasKey( $this->assertEquals(
'key 1', 'key 1',
$pset->perfdata, $pset->perfdata[0]->getLabel(),
'PerfdataSet does not correctly parse non quoted labels with spaces' 'PerfdataSet does not correctly parse non quoted labels with spaces'
); );
$this->assertArrayHasKey( $this->assertEquals(
'key 1 + 1', 'key 1 + 1',
$pset->perfdata, $pset->perfdata[1]->getLabel(),
'PerfdataSet does not correctly parse non quoted labels with spaces' 'PerfdataSet does not correctly parse non quoted labels with spaces'
); );
} }
@ -52,14 +52,14 @@ class PerfdataSetTest extends BaseTestCase
public function testWhetherValidQuotedPerfdataLabelsAreProperlyParsed() public function testWhetherValidQuotedPerfdataLabelsAreProperlyParsed()
{ {
$pset = PerfdataSetWithPublicData::fromString('\'key 1\'=val1 "key 2"=val2'); $pset = PerfdataSetWithPublicData::fromString('\'key 1\'=val1 "key 2"=val2');
$this->assertArrayHasKey( $this->assertEquals(
'key 1', 'key 1',
$pset->perfdata, $pset->perfdata[0]->getLabel(),
'PerfdataSet does not correctly parse valid quoted labels' 'PerfdataSet does not correctly parse valid quoted labels'
); );
$this->assertArrayHasKey( $this->assertEquals(
'key 2', 'key 2',
$pset->perfdata, $pset->perfdata[1]->getLabel(),
'PerfdataSet does not correctly parse valid quoted labels' 'PerfdataSet does not correctly parse valid quoted labels'
); );
} }
@ -67,14 +67,14 @@ class PerfdataSetTest extends BaseTestCase
public function testWhetherInvalidQuotedPerfdataLabelsAreProperlyParsed() public function testWhetherInvalidQuotedPerfdataLabelsAreProperlyParsed()
{ {
$pset = PerfdataSetWithPublicData::fromString('\'key 1=val1 key 2"=val2'); $pset = PerfdataSetWithPublicData::fromString('\'key 1=val1 key 2"=val2');
$this->assertArrayHasKey( $this->assertEquals(
'key 1', 'key 1',
$pset->perfdata, $pset->perfdata[0]->getLabel(),
'PerfdataSet does not correctly parse invalid quoted labels' 'PerfdataSet does not correctly parse invalid quoted labels'
); );
$this->assertArrayHasKey( $this->assertEquals(
'key 2"', 'key 2"',
$pset->perfdata, $pset->perfdata[1]->getLabel(),
'PerfdataSet does not correctly parse invalid quoted labels' 'PerfdataSet does not correctly parse invalid quoted labels'
); );
} }
@ -85,8 +85,8 @@ class PerfdataSetTest extends BaseTestCase
public function testWhetherAPerfdataSetIsIterable() public function testWhetherAPerfdataSetIsIterable()
{ {
$pset = PerfdataSet::fromString('key=value'); $pset = PerfdataSet::fromString('key=value');
foreach ($pset as $label => $value) { foreach ($pset as $p) {
$this->assertEquals('key', $label); $this->assertEquals('key', $p->getLabel());
return; return;
} }

View File

@ -10,142 +10,189 @@ use Icinga\Module\Monitoring\Plugin\Perfdata;
class PerfdataTest extends BaseTestCase class PerfdataTest extends BaseTestCase
{ {
/** /**
* @expectedException Icinga\Exception\ProgrammingError * @expectedException \InvalidArgumentException
*/ */
public function testWhetherFromStringThrowsExceptionWhenGivenAnEmptyString() public function testWhetherFromStringThrowsExceptionWhenGivenAnEmptyString()
{ {
Perfdata::fromString(''); Perfdata::fromString('');
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testWhetherFromStringThrowsExceptionWhenGivenAnInvalidString()
{
Perfdata::fromString('test');
}
public function testWhetherFromStringParsesAGivenStringCorrectly()
{
$p = Perfdata::fromString('key=1234');
$this->assertEquals(
'key',
$p->getLabel(),
'Perfdata::fromString does not properly parse performance data labels'
);
$this->assertEquals(
1234,
$p->getValue(),
'Perfdata::fromString does not properly parse performance data values'
);
}
/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testWhetherGetValueReturnsValidValues() public function testWhetherGetValueReturnsValidValues()
{ {
$this->assertEquals( $this->assertEquals(
1337.0, 1337.0,
Perfdata::fromString('1337')->getValue(), Perfdata::fromString('test=1337')->getValue(),
'Perfdata::getValue does not return correct values' 'Perfdata::getValue does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
1337.0, 1337.0,
Perfdata::fromString('1337;;;;')->getValue(), Perfdata::fromString('test=1337;;;;')->getValue(),
'Perfdata::getValue does not return correct values' 'Perfdata::getValue does not return correct values'
); );
} }
/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testWhetherDecimalValuesAreCorrectlyParsed() public function testWhetherDecimalValuesAreCorrectlyParsed()
{ {
$this->assertEquals( $this->assertEquals(
1337.5, 1337.5,
Perfdata::fromString('1337.5')->getValue(), Perfdata::fromString('test=1337.5')->getValue(),
'Perfdata objects do not parse decimal values correctly' 'Perfdata objects do not parse decimal values correctly'
); );
$this->assertEquals( $this->assertEquals(
1337.5, 1337.5,
Perfdata::fromString('1337.5B')->getValue(), Perfdata::fromString('test=1337.5B')->getValue(),
'Perfdata objects do not parse decimal values correctly' 'Perfdata objects do not parse decimal values correctly'
); );
} }
/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testWhetherGetValueReturnsNullForInvalidOrUnknownValues() public function testWhetherGetValueReturnsNullForInvalidOrUnknownValues()
{ {
$this->assertNull( $this->assertNull(
Perfdata::fromString('U')->getValue(), Perfdata::fromString('test=U')->getValue(),
'Perfdata::getValue does not return null for unknown values' 'Perfdata::getValue does not return null for unknown values'
); );
$this->assertNull( $this->assertNull(
Perfdata::fromString('i am not a value')->getValue(), Perfdata::fromString('test=i am not a value')->getValue(),
'Perfdata::getValue does not return null for invalid values' 'Perfdata::getValue does not return null for invalid values'
); );
} }
/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testWhetherGetWarningTresholdReturnsCorrectValues() public function testWhetherGetWarningTresholdReturnsCorrectValues()
{ {
$this->assertEquals( $this->assertEquals(
'10', '10',
Perfdata::fromString('1;10')->getWarningThreshold(), Perfdata::fromString('test=1;10')->getWarningThreshold(),
'Perfdata::getWarningTreshold does not return correct values' 'Perfdata::getWarningTreshold does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
'10:', '10:',
Perfdata::fromString('1;10:')->getWarningThreshold(), Perfdata::fromString('test=1;10:')->getWarningThreshold(),
'Perfdata::getWarningTreshold does not return correct values' 'Perfdata::getWarningTreshold does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
'~:10', '~:10',
Perfdata::fromString('1;~:10')->getWarningThreshold(), Perfdata::fromString('test=1;~:10')->getWarningThreshold(),
'Perfdata::getWarningTreshold does not return correct values' 'Perfdata::getWarningTreshold does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
'10:20', '10:20',
Perfdata::fromString('1;10:20')->getWarningThreshold(), Perfdata::fromString('test=1;10:20')->getWarningThreshold(),
'Perfdata::getWarningTreshold does not return correct values' 'Perfdata::getWarningTreshold does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
'@10:20', '@10:20',
Perfdata::fromString('1;@10:20')->getWarningThreshold(), Perfdata::fromString('test=1;@10:20')->getWarningThreshold(),
'Perfdata::getWarningTreshold does not return correct values' 'Perfdata::getWarningTreshold does not return correct values'
); );
} }
/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testWhetherGetCriticalTresholdReturnsCorrectValues() public function testWhetherGetCriticalTresholdReturnsCorrectValues()
{ {
$this->assertEquals( $this->assertEquals(
'10', '10',
Perfdata::fromString('1;;10')->getCriticalThreshold(), Perfdata::fromString('test=1;;10')->getCriticalThreshold(),
'Perfdata::getCriticalTreshold does not return correct values' 'Perfdata::getCriticalTreshold does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
'10:', '10:',
Perfdata::fromString('1;;10:')->getCriticalThreshold(), Perfdata::fromString('test=1;;10:')->getCriticalThreshold(),
'Perfdata::getCriticalTreshold does not return correct values' 'Perfdata::getCriticalTreshold does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
'~:10', '~:10',
Perfdata::fromString('1;;~:10')->getCriticalThreshold(), Perfdata::fromString('test=1;;~:10')->getCriticalThreshold(),
'Perfdata::getCriticalTreshold does not return correct values' 'Perfdata::getCriticalTreshold does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
'10:20', '10:20',
Perfdata::fromString('1;;10:20')->getCriticalThreshold(), Perfdata::fromString('test=1;;10:20')->getCriticalThreshold(),
'Perfdata::getCriticalTreshold does not return correct values' 'Perfdata::getCriticalTreshold does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
'@10:20', '@10:20',
Perfdata::fromString('1;;@10:20')->getCriticalThreshold(), Perfdata::fromString('test=1;;@10:20')->getCriticalThreshold(),
'Perfdata::getCriticalTreshold does not return correct values' 'Perfdata::getCriticalTreshold does not return correct values'
); );
} }
/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testWhetherGetMinimumValueReturnsCorrectValues() public function testWhetherGetMinimumValueReturnsCorrectValues()
{ {
$this->assertEquals( $this->assertEquals(
1337.0, 1337.0,
Perfdata::fromString('1;;;1337')->getMinimumValue(), Perfdata::fromString('test=1;;;1337')->getMinimumValue(),
'Perfdata::getMinimumValue does not return correct values' 'Perfdata::getMinimumValue does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
1337.5, 1337.5,
Perfdata::fromString('1;;;1337.5')->getMinimumValue(), Perfdata::fromString('test=1;;;1337.5')->getMinimumValue(),
'Perfdata::getMinimumValue does not return correct values' 'Perfdata::getMinimumValue does not return correct values'
); );
} }
/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testWhetherGetMaximumValueReturnsCorrectValues() public function testWhetherGetMaximumValueReturnsCorrectValues()
{ {
$this->assertEquals( $this->assertEquals(
1337.0, 1337.0,
Perfdata::fromString('1;;;;1337')->getMaximumValue(), Perfdata::fromString('test=1;;;;1337')->getMaximumValue(),
'Perfdata::getMaximumValue does not return correct values' 'Perfdata::getMaximumValue does not return correct values'
); );
$this->assertEquals( $this->assertEquals(
1337.5, 1337.5,
Perfdata::fromString('1;;;;1337.5')->getMaximumValue(), Perfdata::fromString('test=1;;;;1337.5')->getMaximumValue(),
'Perfdata::getMaximumValue does not return correct values' 'Perfdata::getMaximumValue does not return correct values'
); );
} }
/**
* @depends testWhetherFromStringParsesAGivenStringCorrectly
*/
public function testWhetherMissingValuesAreReturnedAsNull() public function testWhetherMissingValuesAreReturnedAsNull()
{ {
$perfdata = Perfdata::fromString('1;;3;5'); $perfdata = Perfdata::fromString('test=1;;3;5');
$this->assertNull( $this->assertNull(
$perfdata->getWarningThreshold(), $perfdata->getWarningThreshold(),
'Perfdata objects do not return null for missing warning tresholds' 'Perfdata objects do not return null for missing warning tresholds'
@ -162,7 +209,7 @@ class PerfdataTest extends BaseTestCase
public function testWhetherValuesAreIdentifiedAsNumber() public function testWhetherValuesAreIdentifiedAsNumber()
{ {
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('666')->isNumber(), Perfdata::fromString('test=666')->isNumber(),
'Perfdata objects do not identify ordinary digits as number' 'Perfdata objects do not identify ordinary digits as number'
); );
} }
@ -173,15 +220,15 @@ class PerfdataTest extends BaseTestCase
public function testWhetherValuesAreIdentifiedAsSeconds() public function testWhetherValuesAreIdentifiedAsSeconds()
{ {
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('666s')->isSeconds(), Perfdata::fromString('test=666s')->isSeconds(),
'Perfdata objects do not identify seconds as seconds' 'Perfdata objects do not identify seconds as seconds'
); );
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('666us')->isSeconds(), Perfdata::fromString('test=666us')->isSeconds(),
'Perfdata objects do not identify microseconds as seconds' 'Perfdata objects do not identify microseconds as seconds'
); );
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('666ms')->isSeconds(), Perfdata::fromString('test=666ms')->isSeconds(),
'Perfdata objects do not identify milliseconds as seconds' 'Perfdata objects do not identify milliseconds as seconds'
); );
} }
@ -192,7 +239,7 @@ class PerfdataTest extends BaseTestCase
public function testWhetherValuesAreIdentifiedAsPercentage() public function testWhetherValuesAreIdentifiedAsPercentage()
{ {
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('66%')->isPercentage(), Perfdata::fromString('test=66%')->isPercentage(),
'Perfdata objects do not identify percentages as percentages' 'Perfdata objects do not identify percentages as percentages'
); );
} }
@ -202,7 +249,7 @@ class PerfdataTest extends BaseTestCase
*/ */
public function testWhetherMinAndMaxAreNotRequiredIfUnitIsInPercent() public function testWhetherMinAndMaxAreNotRequiredIfUnitIsInPercent()
{ {
$perfdata = Perfdata::fromString('1%'); $perfdata = Perfdata::fromString('test=1%');
$this->assertEquals( $this->assertEquals(
0.0, 0.0,
$perfdata->getMinimumValue(), $perfdata->getMinimumValue(),
@ -221,23 +268,23 @@ class PerfdataTest extends BaseTestCase
public function testWhetherValuesAreIdentifiedAsBytes() public function testWhetherValuesAreIdentifiedAsBytes()
{ {
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('66666B')->isBytes(), Perfdata::fromString('test=66666B')->isBytes(),
'Perfdata objects do not identify bytes as bytes' 'Perfdata objects do not identify bytes as bytes'
); );
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('6666KB')->isBytes(), Perfdata::fromString('test=6666KB')->isBytes(),
'Perfdata objects do not identify kilobytes as bytes' 'Perfdata objects do not identify kilobytes as bytes'
); );
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('666MB')->isBytes(), Perfdata::fromString('test=666MB')->isBytes(),
'Perfdata objects do not identify megabytes as bytes' 'Perfdata objects do not identify megabytes as bytes'
); );
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('66GB')->isBytes(), Perfdata::fromString('test=66GB')->isBytes(),
'Perfdata objects do not identify gigabytes as bytes' 'Perfdata objects do not identify gigabytes as bytes'
); );
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('6TB')->isBytes(), Perfdata::fromString('test=6TB')->isBytes(),
'Perfdata objects do not identify terabytes as bytes' 'Perfdata objects do not identify terabytes as bytes'
); );
} }
@ -248,7 +295,7 @@ class PerfdataTest extends BaseTestCase
public function testWhetherValuesAreIdentifiedAsCounter() public function testWhetherValuesAreIdentifiedAsCounter()
{ {
$this->assertTrue( $this->assertTrue(
Perfdata::fromString('123c')->isCounter(), Perfdata::fromString('test=123c')->isCounter(),
'Perfdata objects do not identify counters as counters' 'Perfdata objects do not identify counters as counters'
); );
} }
@ -260,7 +307,7 @@ class PerfdataTest extends BaseTestCase
{ {
$this->assertEquals( $this->assertEquals(
666 / pow(10, 6), 666 / pow(10, 6),
Perfdata::fromString('666us')->getValue(), Perfdata::fromString('test=666us')->getValue(),
'Perfdata objects do not correctly convert microseconds to seconds' 'Perfdata objects do not correctly convert microseconds to seconds'
); );
} }
@ -272,7 +319,7 @@ class PerfdataTest extends BaseTestCase
{ {
$this->assertEquals( $this->assertEquals(
666 / pow(10, 3), 666 / pow(10, 3),
Perfdata::fromString('666ms')->getValue(), Perfdata::fromString('test=666ms')->getValue(),
'Perfdata objects do not correctly convert microseconds to seconds' 'Perfdata objects do not correctly convert microseconds to seconds'
); );
} }
@ -284,20 +331,20 @@ class PerfdataTest extends BaseTestCase
{ {
$this->assertEquals( $this->assertEquals(
66.0, 66.0,
Perfdata::fromString('66%')->getPercentage(), Perfdata::fromString('test=66%')->getPercentage(),
'Perfdata objects do not correctly handle native percentages' 'Perfdata objects do not correctly handle native percentages'
); );
$this->assertEquals( $this->assertEquals(
50.0, 50.0,
Perfdata::fromString('0;;;-250;250')->getPercentage(), Perfdata::fromString('test=0;;;-250;250')->getPercentage(),
'Perfdata objects do not correctly convert suitable values to percentages' 'Perfdata objects do not correctly convert suitable values to percentages'
); );
$this->assertNull( $this->assertNull(
Perfdata::fromString('50')->getPercentage(), Perfdata::fromString('test=50')->getPercentage(),
'Perfdata objects do return a percentage though their unit is not % and no maximum is given' 'Perfdata objects do return a percentage though their unit is not % and no maximum is given'
); );
$this->assertNull( $this->assertNull(
Perfdata::fromString('25;;;50;100')->getPercentage(), Perfdata::fromString('test=25;;;50;100')->getPercentage(),
'Perfdata objects do return a percentage though their value is lower than it\'s allowed minimum' 'Perfdata objects do return a percentage though their value is lower than it\'s allowed minimum'
); );
} }
@ -309,7 +356,7 @@ class PerfdataTest extends BaseTestCase
{ {
$this->assertEquals( $this->assertEquals(
6666.0 * pow(2, 10), 6666.0 * pow(2, 10),
Perfdata::fromString('6666KB')->getValue(), Perfdata::fromString('test=6666KB')->getValue(),
'Perfdata objects do not corretly convert kilobytes to bytes' 'Perfdata objects do not corretly convert kilobytes to bytes'
); );
} }
@ -321,7 +368,7 @@ class PerfdataTest extends BaseTestCase
{ {
$this->assertEquals( $this->assertEquals(
666.0 * pow(2, 20), 666.0 * pow(2, 20),
Perfdata::fromString('666MB')->getValue(), Perfdata::fromString('test=666MB')->getValue(),
'Perfdata objects do not corretly convert megabytes to bytes' 'Perfdata objects do not corretly convert megabytes to bytes'
); );
} }
@ -333,7 +380,7 @@ class PerfdataTest extends BaseTestCase
{ {
$this->assertEquals( $this->assertEquals(
66.0 * pow(2, 30), 66.0 * pow(2, 30),
Perfdata::fromString('66GB')->getValue(), Perfdata::fromString('test=66GB')->getValue(),
'Perfdata objects do not corretly convert gigabytes to bytes' 'Perfdata objects do not corretly convert gigabytes to bytes'
); );
} }
@ -345,7 +392,7 @@ class PerfdataTest extends BaseTestCase
{ {
$this->assertEquals( $this->assertEquals(
6.0 * pow(2, 40), 6.0 * pow(2, 40),
Perfdata::fromString('6TB')->getValue(), Perfdata::fromString('test=6TB')->getValue(),
'Perfdata objects do not corretly convert terabytes to bytes' 'Perfdata objects do not corretly convert terabytes to bytes'
); );
} }