mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #4873 from laf/issue-4868
fix: Toner graphs with invalid chars
This commit is contained in:
@@ -46,7 +46,7 @@ foreach (dbFetchRows('SELECT * FROM toner where device_id = ?', array($device['d
|
||||
|
||||
$hostname = gethostbyid($toner['device_id']);
|
||||
|
||||
$descr = substr(str_pad($toner['toner_descr'], 16), 0, 16);
|
||||
$descr = safedescr(substr(str_pad($toner['toner_descr'], 16), 0, 16));
|
||||
$rrd_filename = rrd_name($device['hostname'], array('toner', $toner['toner_index']));
|
||||
$toner_id = $toner['toner_id'];
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ if ($colour['left'] == null) {
|
||||
$colour['left'] = 'CC0000';
|
||||
}
|
||||
|
||||
$descr = substr(str_pad($toner['toner_descr'], 26), 0, 26);
|
||||
$descr = safedescr(substr(str_pad($toner['toner_descr'], 26), 0, 26));
|
||||
|
||||
$background = get_percentage_colours((100 - $toner['toner_current']));
|
||||
|
||||
|
||||
@@ -490,6 +490,16 @@ function safename($name)
|
||||
return preg_replace('/[^a-zA-Z0-9,._\-]/', '_', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function format the rrdtool description text correctly.
|
||||
* @param $descr
|
||||
* @return mixed
|
||||
*/
|
||||
function safedescr($descr)
|
||||
{
|
||||
return preg_replace('/[^a-zA-Z0-9,._\-\/\ ]/', ' ', $descr);
|
||||
}
|
||||
|
||||
function zeropad($num, $length = 2)
|
||||
{
|
||||
while (strlen($num) < $length) {
|
||||
|
||||
@@ -77,4 +77,10 @@ class CommonFunctionsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(ends_with($data, array('this', 'tesTing', 'no'), true));
|
||||
$this->assertFalse(ends_with($data, array('this', 'Test'), true));
|
||||
}
|
||||
|
||||
public function testRrdDescriptions()
|
||||
{
|
||||
$data = 'Toner, S/N:CR_UM-16021314488.';
|
||||
$this->assertEquals('Toner, S/N CR_UM-16021314488.', safedescr($data));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user