New upstream version 0.6.27
This commit is contained in:
@@ -1,58 +1,79 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
<?php
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
defined('SYSPATH') or die('No direct access allowed.');
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
class nagios_Core {
|
||||
|
||||
public static function SummaryLink($hostname,$start,$end){
|
||||
class nagios_Core
|
||||
{
|
||||
public static function SummaryLink($hostname, $start, $end)
|
||||
{
|
||||
$config = new Config_Model();
|
||||
$config->read_config();
|
||||
|
||||
$smon = date('m' , $start);
|
||||
$sday = date('d' , $start);
|
||||
$syear = date('Y' , $start);
|
||||
$shour = date('G' , $start);
|
||||
$smin = date('i' , $start);
|
||||
$ssec = date('s' , $start);
|
||||
$emon = date('m' , $end);
|
||||
$eday = date('d' , $end);
|
||||
$eyear = date('Y' , $end);
|
||||
$ehour = date('G' , $end);
|
||||
$emin = date('i' , $end);
|
||||
$esec = date('s' , $end);
|
||||
$smon = date('m', $start);
|
||||
$sday = date('d', $start);
|
||||
$syear = date('Y', $start);
|
||||
$shour = date('G', $start);
|
||||
$smin = date('i', $start);
|
||||
$ssec = date('s', $start);
|
||||
$emon = date('m', $end);
|
||||
$eday = date('d', $end);
|
||||
$eyear = date('Y', $end);
|
||||
$ehour = date('G', $end);
|
||||
$emin = date('i', $end);
|
||||
$esec = date('s', $end);
|
||||
$nagios_base = $config->conf['nagios_base'];
|
||||
print "<a href=\"$nagios_base/summary.cgi?report=1&displaytype=1&timeperiod=custom&smon=$smon&sday=$sday&syear=$syear&shour=$shour&smin=$smin&ssec=$ssec&emon=$emon&eday=$eday&eyear=$eyear&ehour=$ehour&emin=$emin&esec=$esec&hostgroup=all&servicegroup=all&host=$hostname&alerttypes=3&statetypes=3&hoststates=7&servicestates=120&limit=999\"";
|
||||
print " title=\"".Kohana::lang('common.nagios-summary-link-title')."\"><img src=\"".url::base()."media/images/notify.gif\"></a>\n";
|
||||
print "<a href=\"$nagios_base/summary.cgi?report=1&displaytype=1" .
|
||||
"&timeperiod=custom&smon=$smon&sday=$sday&syear=$syear&shour=$shour" .
|
||||
"&smin=$smin&ssec=$ssec&emon=$emon&eday=$eday&eyear=$eyear&ehour=$ehour" .
|
||||
"&emin=$emin&esec=$esec&hostgroup=all&servicegroup=all&host=$hostname" .
|
||||
"&alerttypes=3&statetypes=3&hoststates=7&servicestates=120&limit=999\"";
|
||||
print " title=\"" . Kohana::lang('common.nagios-summary-link-title') . "\"><img src=\"" . url::base() . "media/images/notify.gif\"></a>\n";
|
||||
}
|
||||
|
||||
public static function AvailLink($hostname,$servicedesc,$start,$end){
|
||||
public static function AvailLink($hostname, $servicedesc, $start, $end)
|
||||
{
|
||||
$config = new Config_Model();
|
||||
$config->read_config();
|
||||
$hostname = urlencode($hostname);
|
||||
$servicedesc = urlencode($servicedesc);
|
||||
$smon = date('m' , $start);
|
||||
$sday = date('d' , $start);
|
||||
$syear = date('Y' , $start);
|
||||
$shour = date('G' , $start);
|
||||
$smin = date('i' , $start);
|
||||
$ssec = date('s' , $start);
|
||||
$emon = date('m' , $end);
|
||||
$eday = date('d' , $end);
|
||||
$eyear = date('Y' , $end);
|
||||
$ehour = date('G' , $end);
|
||||
$emin = date('i' , $end);
|
||||
$esec = date('s' , $end);
|
||||
$hostname = urlencode($hostname);
|
||||
$servicedesc = urlencode($servicedesc);
|
||||
$smon = date('m', $start);
|
||||
$sday = date('d', $start);
|
||||
$syear = date('Y', $start);
|
||||
$shour = date('G', $start);
|
||||
$smin = date('i', $start);
|
||||
$ssec = date('s', $start);
|
||||
$emon = date('m', $end);
|
||||
$eday = date('d', $end);
|
||||
$eyear = date('Y', $end);
|
||||
$ehour = date('G', $end);
|
||||
$emin = date('i', $end);
|
||||
$esec = date('s', $end);
|
||||
$nagios_base = $config->conf['nagios_base'];
|
||||
if($servicedesc == "Host+Perfdata"){
|
||||
print "<a href=\"$nagios_base/avail.cgi?show_log_entries=&host=$hostname&timeperiod=custom&smon=$smon&sday=$sday&syear=$syear&shour=$shour&smin=$smin&ssec=$ssec&emon=$emon&eday=$eday&eyear=$eyear&ehour=$ehour&emin=$emin&esec=$esec&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=yes&initialassumedservicestate=6&backtrack=4\"";
|
||||
}else{
|
||||
print "<a href=\"$nagios_base/avail.cgi?show_log_entries=&host=$hostname&service=$servicedesc&timeperiod=custom&smon=$smon&sday=$sday&syear=$syear&shour=$shour&smin=$smin&ssec=$ssec&emon=$emon&eday=$eday&eyear=$eyear&ehour=$ehour&emin=$emin&esec=$esec&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes&assumestatesduringnotrunning=yes&includesoftstates=yes&initialassumedservicestate=6&backtrack=4\"";
|
||||
|
||||
if ($servicedesc == "Host+Perfdata") {
|
||||
print "<a href=\"$nagios_base/avail.cgi?show_log_entries=" .
|
||||
"&host=$hostname&timeperiod=custom&smon=$smon&sday=$sday" .
|
||||
"&syear=$syear&shour=$shour&smin=$smin&ssec=$ssec&emon=$emon" .
|
||||
"&eday=$eday&eyear=$eyear&ehour=$ehour&emin=$emin&esec=$esec" .
|
||||
"&rpttimeperiod=&assumeinitialstates=yes&assumestateretention=yes" .
|
||||
"&assumestatesduringnotrunning=yes&includesoftstates=yes" .
|
||||
"&initialassumedservicestate=6&backtrack=4\"";
|
||||
} else {
|
||||
print "<a href=\"$nagios_base/avail.cgi?show_log_entries=" .
|
||||
"&host=$hostname&service=$servicedesc&timeperiod=custom" .
|
||||
"&smon=$smon&sday=$sday&syear=$syear&shour=$shour&smin=$smin" .
|
||||
"&ssec=$ssec&emon=$emon&eday=$eday&eyear=$eyear&ehour=$ehour" .
|
||||
"&emin=$emin&esec=$esec&rpttimeperiod=&assumeinitialstates=yes" .
|
||||
"&assumestateretention=yes&assumestatesduringnotrunning=yes" .
|
||||
"&includesoftstates=yes&initialassumedservicestate=6&backtrack=4\"";
|
||||
}
|
||||
print " title=\"".Kohana::lang('common.nagios-avail-link-title')."\"><img src=\"".url::base()."media/images/trends.gif\" ></a>\n";
|
||||
print " title=\"" . Kohana::lang('common.nagios-avail-link-title') . "\"><img src=\"" . url::base() . "media/images/trends.gif\" ></a>\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,35 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
<?php
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
defined('SYSPATH') or die('No direct access allowed.');
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
class pnp_Core {
|
||||
|
||||
public static function clean($string = FALSE){
|
||||
if($string === FALSE){
|
||||
class pnp_Core
|
||||
{
|
||||
public static function clean($string = false)
|
||||
{
|
||||
if ($string === false) {
|
||||
return;
|
||||
}
|
||||
if($string == ""){
|
||||
if ($string == "") {
|
||||
return $string;
|
||||
}
|
||||
$string = preg_replace('/[ :\/\\\]/', "_", $string);
|
||||
$string = htmlspecialchars($string);
|
||||
return $string;
|
||||
|
||||
}
|
||||
public static function shorten($string = FALSE, $length = 25){
|
||||
if($string === FALSE){
|
||||
public static function shorten($string = false, $length = 25)
|
||||
{
|
||||
if ($string === false) {
|
||||
return;
|
||||
}
|
||||
if(strlen($string) > $length){
|
||||
if (strlen($string) > $length) {
|
||||
$string = substr($string, 0, $length) . "...";
|
||||
}
|
||||
return $string;
|
||||
@@ -29,13 +37,14 @@ class pnp_Core {
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static function xml_version_check($string = FALSE){
|
||||
if($string === FALSE){
|
||||
return FALSE;
|
||||
public static function xml_version_check($string = false)
|
||||
{
|
||||
if ($string === false) {
|
||||
return false;
|
||||
}
|
||||
if( $string == XML_STRUCTURE_VERSION ){
|
||||
if ($string == XML_STRUCTURE_VERSION) {
|
||||
$string = "valid";
|
||||
}else{
|
||||
} else {
|
||||
$string = Kohana::lang('error.xml-structure-mismatch', $string, XML_STRUCTURE_VERSION);
|
||||
}
|
||||
return $string;
|
||||
@@ -43,66 +52,85 @@ class pnp_Core {
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static function zoom_icon($host,$service,$start,$end,$source,$view,$graph_width,$graph_height){
|
||||
public static function zoom_icon($host, $service, $start, $end, $source, $view, $graph_width, $graph_height)
|
||||
{
|
||||
$service = urlencode(urlencode($service));
|
||||
$host = urlencode(urlencode($host));
|
||||
print "<a href=\"javascript:Gzoom('".url::base(TRUE)."zoom?host=$host&srv=$service&view=$view&source=$source&end=$end&start=$start&graph_width=$graph_width&graph_height=$graph_height');\" title=\"Zoom into the Graph\"><img src=\"".url::base()."media/images/zoom.png\"></a>\n";
|
||||
print "<a href=\"javascript:Gzoom('" . url::base(true) .
|
||||
"zoom?host=$host&srv=$service&view=$view&source=$source&end=$end&start=$start" .
|
||||
"&graph_width=$graph_width&graph_height=$graph_height');\" title=\"Zoom into the Graph\"><img src=\"" .
|
||||
url::base() . "media/images/zoom.png\"></a>\n";
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static function zoom_icon_special($tpl,$start,$end,$source,$view,$graph_width,$graph_height){
|
||||
print "<a href=\"javascript:Gzoom('".url::base(TRUE)."zoom?tpl=$tpl&view=$view&source=$source&end=$end&start=$start&graph_width=$graph_width&graph_height=$graph_height');\" title=\"Zoom into the Graph\"><img src=\"".url::base()."media/images/zoom.png\"></a>\n";
|
||||
public static function zoom_icon_special($tpl, $start, $end, $source, $view, $graph_width, $graph_height)
|
||||
{
|
||||
print "<a href=\"javascript:Gzoom('" . url::base(true) .
|
||||
"zoom?tpl=$tpl&view=$view&source=$source&end=$end&start=$start" .
|
||||
"&graph_width=$graph_width&graph_height=$graph_height');\" title=\"Zoom into the Graph\">" .
|
||||
"<img src=\"" . url::base() . "media/images/zoom.png\"></a>\n";
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static function add_to_basket_icon($host,$service,$source=FALSE){
|
||||
if($source === FALSE){
|
||||
print "<span id=\"basket_action_add\"><a title=\"".Kohana::lang('common.basket-add-service')."\" id=\"".$host."::".$service."\"><img width=12px height=12px src=\"".url::base()."media/images/add.png\"></a></span>\n";
|
||||
}else{
|
||||
print "<span id=\"basket_action_add\"><a title=\"".Kohana::lang('common.basket-add-item')."\" id=\"".$host."::".$service."::".$source."\"><img width=16px height=16px src=\"".url::base()."media/images/add.png\"></a></span>\n";
|
||||
public static function add_to_basket_icon($host, $service, $source = false)
|
||||
{
|
||||
if ($source === false) {
|
||||
print "<span id=\"basket_action_add\"><a title=\"" .
|
||||
Kohana::lang('common.basket-add-service') .
|
||||
"\" id=\"" . $host . "::" . $service .
|
||||
"\"><img width=12px height=12px src=\"" .
|
||||
url::base() . "media/images/add.png\"></a></span>\n";
|
||||
} else {
|
||||
print "<span id=\"basket_action_add\"><a title=\"" .
|
||||
Kohana::lang('common.basket-add-item') .
|
||||
"\" id=\"" . $host . "::" . $service . "::" .
|
||||
$source . "\"><img width=16px height=16px src=\"" .
|
||||
url::base() . "media/images/add.png\"></a></span>\n";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static function multisite_link($base_url=FALSE,$site=FALSE,$host=FALSE,$service=FALSE){
|
||||
if($host && $service){
|
||||
$link = sprintf("'%s/view.py?view_name=service&site=%s&host=%s&service=%s'", $base_url,$site,urlencode($host),urlencode($service));
|
||||
public static function multisite_link($base_url = false, $site = false, $host = false, $service = false)
|
||||
{
|
||||
if ($host && $service) {
|
||||
$link = sprintf("'%s/view.py?view_name=service&site=%s&host=%s&service=%s'", $base_url, $site, urlencode($host), urlencode($service));
|
||||
return $link;
|
||||
}
|
||||
if($host){
|
||||
$link = sprintf("'%s/view.py?view_name=host&site=%s&host=%s'", $base_url,$site,urlencode($host));
|
||||
if ($host) {
|
||||
$link = sprintf("'%s/view.py?view_name=host&site=%s&host=%s'", $base_url, $site, urlencode($host));
|
||||
return $link;
|
||||
}
|
||||
}
|
||||
|
||||
public static function addToUri($fields = array(),$base = True){
|
||||
if(!is_array($fields)){
|
||||
public static function addToUri($fields = array(), $base = true)
|
||||
{
|
||||
if (!is_array($fields)) {
|
||||
return false;
|
||||
}
|
||||
$get = $_GET;
|
||||
if($base === True){
|
||||
$uri = url::base(TRUE);
|
||||
if ($base === true) {
|
||||
$uri = url::base(true);
|
||||
$uri .= Router::$current_uri;
|
||||
}else{
|
||||
} else {
|
||||
$uri = "";
|
||||
}
|
||||
$uri .= '?';
|
||||
foreach($fields as $key=>$value){
|
||||
foreach ($fields as $key => $value) {
|
||||
$get[$key] = $value;
|
||||
}
|
||||
foreach($get as $key=>$value){
|
||||
if($value === ''){
|
||||
continue;
|
||||
}
|
||||
$uri .= $key."=".urlencode($value)."&";
|
||||
foreach ($get as $key => $value) {
|
||||
if ($value === '') {
|
||||
continue;
|
||||
}
|
||||
$uri .= $key . "=" . urlencode($value) . "&";
|
||||
}
|
||||
return rtrim($uri,"&");
|
||||
return rtrim($uri, "&");
|
||||
}
|
||||
|
||||
/* "normalize" and adjust value / unit (similar to format string %s in RRDtool)
|
||||
@@ -117,12 +145,13 @@ class pnp_Core {
|
||||
* unit := adjusted unit
|
||||
* divisor := number used to "normalize" value
|
||||
*/
|
||||
public static function adjust_unit($value,$base=1000,$format='%.3lf'){
|
||||
preg_match('/^(-?[0-9\.,]+)\s*(\S?)(\S?)/',$value,$matches);
|
||||
public static function adjust_unit($value, $base = 1000, $format = '%.3lf')
|
||||
{
|
||||
preg_match('/^(-?[0-9\.,]+)\s*(\S?)(\S?)/', $value, $matches);
|
||||
|
||||
$mag = 0;
|
||||
$value = $matches[1];
|
||||
while ($value >= $base){
|
||||
while ($value >= $base) {
|
||||
$value /= $base;
|
||||
$mag++;
|
||||
}
|
||||
@@ -137,17 +166,17 @@ class pnp_Core {
|
||||
$matches[3] = $matches[2];
|
||||
$matches[2] = " ";
|
||||
}
|
||||
$pos = strpos(' KMGTP',strtoupper($matches[2]));
|
||||
$unit = substr(' KMGTP',$mag+$pos,1).$matches[3];
|
||||
$pos = strpos(' KMGTP', strtoupper($matches[2]));
|
||||
$unit = substr(' KMGTP', $mag + $pos, 1) . $matches[3];
|
||||
}
|
||||
$val_unit = sprintf ("$format %s", $value, $unit);
|
||||
$val_fmt = sprintf ($format, $value);
|
||||
$val_fmt = str_replace(' ','',$val_fmt);
|
||||
return array ($val_unit,$val_fmt,$unit,pow($base,$mag));
|
||||
$val_unit = sprintf("$format %s", $value, $unit);
|
||||
$val_fmt = sprintf($format, $value);
|
||||
$val_fmt = str_replace(' ', '', $val_fmt);
|
||||
return array ($val_unit,$val_fmt,$unit,pow($base, $mag));
|
||||
}
|
||||
|
||||
public static function print_version(){
|
||||
return PNP_NAME . "-" . PNP_VERSION . " [ " . PNP_REL_DATE . " ]";
|
||||
public static function print_version()
|
||||
{
|
||||
return PNP_NAME . "-" . PNP_VERSION . " [ " . PNP_REL_DATE . " ]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,456 +1,519 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
<?php
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
defined('SYSPATH') or die('No direct access allowed.');
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
|
||||
/*
|
||||
*
|
||||
* RRDTool Helper Class
|
||||
* RRDTool Helper Class
|
||||
*/
|
||||
class rrd_Core {
|
||||
|
||||
public static function color_inverse($color){
|
||||
$color = str_replace('#', '', $color);
|
||||
if (strlen($color) != 6){ return '000000'; }
|
||||
$rgb = '';
|
||||
for ($x=0;$x<3;$x++){
|
||||
$c = 255 - hexdec(substr($color,(2*$x),2));
|
||||
$c = ($c < 0) ? 0 : dechex($c);
|
||||
$rgb .= (strlen($c) < 2) ? '0'.$c : $c;
|
||||
}
|
||||
return '#'.$rgb;
|
||||
}
|
||||
class rrd_Core
|
||||
{
|
||||
public static function color_inverse($color)
|
||||
{
|
||||
$color = str_replace('#', '', $color);
|
||||
if (strlen($color) != 6) {
|
||||
return '000000';
|
||||
}
|
||||
$rgb = '';
|
||||
for ($x = 0; $x < 3; $x++) {
|
||||
$c = 255 - hexdec(substr($color, (2 * $x), 2));
|
||||
$c = ($c < 0) ? 0 : dechex($c);
|
||||
$rgb .= (strlen($c) < 2) ? '0' . $c : $c;
|
||||
}
|
||||
return '#' . $rgb;
|
||||
}
|
||||
|
||||
/*
|
||||
* Color Function
|
||||
* Concept by Stefan Triep
|
||||
*/
|
||||
public static function color($num=0 , $alpha='FF', $scheme=''){
|
||||
$colors = array();
|
||||
$value = array('cc','ff','99','66');
|
||||
$num = intval($num);
|
||||
public static function color($num = 0, $alpha = 'FF', $scheme = '')
|
||||
{
|
||||
$colors = array();
|
||||
$value = array('cc','ff','99','66');
|
||||
$num = intval($num);
|
||||
|
||||
# check if colour scheme entry exists
|
||||
# fall back to old method if not found
|
||||
if ( isset( $scheme["$num"] ) ){
|
||||
$color = $scheme["$num"] . $alpha;
|
||||
return $color;
|
||||
}
|
||||
# check if colour scheme entry exists
|
||||
# fall back to old method if not found
|
||||
if (isset($scheme["$num"])) {
|
||||
$color = $scheme["$num"] . $alpha;
|
||||
return $color;
|
||||
}
|
||||
|
||||
foreach($value as $ri){
|
||||
for ($z=1;$z<8;$z++) {
|
||||
$color = "#";
|
||||
if ( ($z & 4) >= 1 ){
|
||||
$color .= "$ri";
|
||||
} else {
|
||||
$color .= "00";
|
||||
}
|
||||
if ( ($z & 2) >= 1 ){
|
||||
$color .= "$ri";
|
||||
} else {
|
||||
$color .= "00";
|
||||
}
|
||||
if ( ($z & 1) >= 1 ){
|
||||
$color .= "$ri";
|
||||
} else {
|
||||
$color .= "00";
|
||||
}
|
||||
$icolor = rrd::color_inverse($color);
|
||||
$pos = array_search($color,$colors);
|
||||
$ipos = array_search($icolor,$colors);
|
||||
if ( $pos == false ) {
|
||||
$colors[] = $color . $alpha;
|
||||
}
|
||||
if ( $ipos == false ) {
|
||||
$colors[] = $icolor . $alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (array_key_exists($num, $colors)) {
|
||||
return $colors[$num];
|
||||
} else {
|
||||
return $colors[0];
|
||||
}
|
||||
}
|
||||
foreach ($value as $ri) {
|
||||
for ($z = 1; $z < 8; $z++) {
|
||||
$color = "#";
|
||||
if (($z & 4) >= 1) {
|
||||
$color .= "$ri";
|
||||
} else {
|
||||
$color .= "00";
|
||||
}
|
||||
if (($z & 2) >= 1) {
|
||||
$color .= "$ri";
|
||||
} else {
|
||||
$color .= "00";
|
||||
}
|
||||
if (($z & 1) >= 1) {
|
||||
$color .= "$ri";
|
||||
} else {
|
||||
$color .= "00";
|
||||
}
|
||||
$icolor = rrd::color_inverse($color);
|
||||
$pos = array_search($color, $colors);
|
||||
$ipos = array_search($icolor, $colors);
|
||||
if ($pos == false) {
|
||||
$colors[] = $color . $alpha;
|
||||
}
|
||||
if ($ipos == false) {
|
||||
$colors[] = $icolor . $alpha;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (array_key_exists($num, $colors)) {
|
||||
return $colors[$num];
|
||||
} else {
|
||||
return $colors[0];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Gradient Function
|
||||
* Concept by Stefan Triep
|
||||
*/
|
||||
public static function gradient($vname=FALSE, $start_color='#0000a0', $end_color='#f0f0f0', $label=FALSE, $steps=20, $lower=FALSE){
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
public static function gradient($vname = false, $start_color = '#0000a0', $end_color = '#f0f0f0', $label = false, $steps = 20, $lower = false)
|
||||
{
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if (preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i', $start_color, $matches)) {
|
||||
$r1 = hexdec($matches[1]);
|
||||
$g1 = hexdec($matches[2]);
|
||||
$b1 = hexdec($matches[3]);
|
||||
} else {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Wrong Color Format: '" . $start_color . "'");
|
||||
}
|
||||
if(preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i',$start_color,$matches)){
|
||||
$r1=hexdec($matches[1]);
|
||||
$g1=hexdec($matches[2]);
|
||||
$b1=hexdec($matches[3]);
|
||||
}else{
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Wrong Color Format: '".$start_color."'");
|
||||
}
|
||||
|
||||
if(preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i',$end_color,$matches)){
|
||||
$r2=hexdec($matches[1]);
|
||||
$g2=hexdec($matches[2]);
|
||||
$b2=hexdec($matches[3]);
|
||||
}else{
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Wrong Color Format: '".$end_color."'");
|
||||
}
|
||||
if (preg_match('/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})/i', $end_color, $matches)) {
|
||||
$r2 = hexdec($matches[1]);
|
||||
$g2 = hexdec($matches[2]);
|
||||
$b2 = hexdec($matches[3]);
|
||||
} else {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Wrong Color Format: '" . $end_color . "'");
|
||||
}
|
||||
|
||||
$diff_r=$r2-$r1;
|
||||
$diff_g=$g2-$g1;
|
||||
$diff_b=$b2-$b1;
|
||||
$diff_r = $r2 - $r1;
|
||||
$diff_g = $g2 - $g1;
|
||||
$diff_b = $b2 - $b1;
|
||||
$spline = "";
|
||||
$spline_vname = "var".substr(sha1(rand()),1,4);
|
||||
if(preg_match('/^([0-9]{1,3})%$/', $lower, $matches)){
|
||||
if($matches[1] > 100)
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Lower gradient start > 100% is not allowed: '".$lower."'");
|
||||
|
||||
$spline_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
if (preg_match('/^([0-9]{1,3})%$/', $lower, $matches)) {
|
||||
if ($matches[1] > 100) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Lower gradient start > 100% is not allowed: '" . $lower . "'");
|
||||
}
|
||||
|
||||
$lower = $matches[1];
|
||||
$spline .= sprintf("CDEF:%sminimum=%s,100,/,%d,* ", $vname, $vname, $lower);
|
||||
}elseif(preg_match('/^([0-9]+)$/', $lower, $matches)){
|
||||
} elseif (preg_match('/^([0-9]+)$/', $lower, $matches)) {
|
||||
$lower = $matches[1];
|
||||
$spline .= sprintf("CDEF:%sminimum=%s,%d,- ", $vname, $vname, $lower);
|
||||
}else{
|
||||
} else {
|
||||
$lower = 0;
|
||||
$spline .= sprintf("CDEF:%sminimum=%s,%s,- ", $vname, $vname, $vname);
|
||||
}
|
||||
# debug
|
||||
# $spline .= sprintf("GPRINT:%sminimum:MAX:\"minumum %%lf\\n\" ",$vname);
|
||||
for ($i=$steps; $i>0; $i--){
|
||||
$spline .= sprintf("CDEF:%s%d=%s,%sminimum,-,%d,/,%d,*,%sminimum,+ ",$spline_vname,$i,$vname,$vname,$steps,$i,$vname );
|
||||
# $spline .= sprintf("GPRINT:%sminimum:MAX:\"minumum %%lf\\n\" ",$vname);
|
||||
for ($i = $steps; $i > 0; $i--) {
|
||||
$spline .= sprintf("CDEF:%s%d=%s,%sminimum,-,%d,/,%d,*,%sminimum,+ ", $spline_vname, $i, $vname, $vname, $steps, $i, $vname);
|
||||
# debug
|
||||
# $spline .= sprintf("GPRINT:%s%d:MAX:\"%22d %%lf\\n\" ",$spline_vname,$i,$i);
|
||||
}
|
||||
for ($i=$steps; $i>0; $i--){
|
||||
$factor=$i / $steps;
|
||||
$r=round($r1 + $diff_r * $factor);
|
||||
$g=round($g1 + $diff_g * $factor);
|
||||
$b=round($b1 + $diff_b * $factor);
|
||||
if (($i==$steps) and ($label!=FALSE)){
|
||||
$spline .= sprintf("AREA:%s%d#%02X%02X%02X:\"%s\" ", $spline_vname,$i,$r,$g,$b,$label);
|
||||
}else{
|
||||
$spline .= sprintf("AREA:%s%d#%02X%02X%02X ", $spline_vname,$i,$r,$g,$b);
|
||||
# $spline .= sprintf("GPRINT:%s%d:MAX:\"%22d %%lf\\n\" ",$spline_vname,$i,$i);
|
||||
}
|
||||
for ($i = $steps; $i > 0; $i--) {
|
||||
$factor = $i / $steps;
|
||||
$r = round($r1 + $diff_r * $factor);
|
||||
$g = round($g1 + $diff_g * $factor);
|
||||
$b = round($b1 + $diff_b * $factor);
|
||||
if (($i == $steps) and ($label != false)) {
|
||||
$spline .= sprintf("AREA:%s%d#%02X%02X%02X:\"%s\" ", $spline_vname, $i, $r, $g, $b, $label);
|
||||
} else {
|
||||
$spline .= sprintf("AREA:%s%d#%02X%02X%02X ", $spline_vname, $i, $r, $g, $b);
|
||||
}
|
||||
}
|
||||
return $spline;
|
||||
}
|
||||
|
||||
|
||||
public static function cut($string, $length=18, $align='left'){
|
||||
if(strlen($string) > $length){
|
||||
$string = substr($string,0,($length-3))."...";
|
||||
public static function cut($string, $length = 18, $align = 'left')
|
||||
{
|
||||
if (strlen($string) > $length) {
|
||||
$string = substr($string, 0, ($length - 3)) . "...";
|
||||
}
|
||||
if($align == 'left'){
|
||||
$format = "%-".$length."s";
|
||||
}else{
|
||||
$format = "%".$length."s";
|
||||
if ($align == 'left') {
|
||||
$format = "%-" . $length . "s";
|
||||
} else {
|
||||
$format = "%" . $length . "s";
|
||||
}
|
||||
$s = sprintf($format,$string);
|
||||
$s = sprintf($format, $string);
|
||||
return $s;
|
||||
}
|
||||
|
||||
public static function area($vname=FALSE, $color=FALSE, $text=FALSE, $stack=FALSE){
|
||||
|
||||
public static function area($vname = false, $color = false, $text = false, $stack = false)
|
||||
{
|
||||
$line = "";
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}else{
|
||||
$line .= "AREA:".$vname;
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
} else {
|
||||
$line .= "AREA:" . $vname;
|
||||
}
|
||||
if($color === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'color' is missing");
|
||||
}else{
|
||||
if ($color === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'color' is missing");
|
||||
} else {
|
||||
$line .= $color;
|
||||
}
|
||||
$line .= ":\"$text\"";
|
||||
if($stack != FALSE){
|
||||
$line .= ":STACK";
|
||||
}
|
||||
$line .= " ";
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function line($type=1,$vname=FALSE, $color=FALSE, $text=FALSE, $stack=FALSE){
|
||||
$line = "";
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}else{
|
||||
$line .= "LINE".$type.":".$vname;
|
||||
}
|
||||
if($color === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'color' is missing");
|
||||
}else{
|
||||
$line .= $color;
|
||||
}
|
||||
$line .= ":\"$text\"";
|
||||
if($stack != FALSE){
|
||||
if ($stack != false) {
|
||||
$line .= ":STACK";
|
||||
}
|
||||
$line .= " ";
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function line1($vname=FALSE, $color=FALSE, $text=FALSE, $stack=FALSE){
|
||||
return rrd::line(1,$vname, $color,$text, $stack);
|
||||
}
|
||||
|
||||
public static function line2($vname=FALSE, $color=FALSE, $text=FALSE, $stack=FALSE){
|
||||
return rrd::line(2,$vname, $color,$text, $stack);
|
||||
}
|
||||
|
||||
public static function line3($vname=FALSE, $color=FALSE, $text=FALSE, $stack=FALSE){
|
||||
return rrd::line(3,$vname, $color,$text, $stack);
|
||||
}
|
||||
|
||||
public static function gprint($vname=FALSE, $cf="AVERAGE", $text="%6.2lf %s"){
|
||||
public static function line($type = 1, $vname = false, $color = false, $text = false, $stack = false)
|
||||
{
|
||||
$line = "";
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
} else {
|
||||
$line .= "LINE" . $type . ":" . $vname;
|
||||
}
|
||||
|
||||
if(is_array($cf)){
|
||||
foreach($cf as $key => $val){
|
||||
$line .= sprintf("GPRINT:%s:%s:",$vname,$val);
|
||||
if($key == sizeof($cf)-1){
|
||||
$line .= '"'.$text.' '.ucfirst(strtolower($val)).'\\l" ';
|
||||
}else{
|
||||
$line .= '"'.$text.' '.ucfirst(strtolower($val)).'" ';
|
||||
if ($color === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'color' is missing");
|
||||
} else {
|
||||
$line .= $color;
|
||||
}
|
||||
$line .= ":\"$text\"";
|
||||
if ($stack != false) {
|
||||
$line .= ":STACK";
|
||||
}
|
||||
$line .= " ";
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function line1($vname = false, $color = false, $text = false, $stack = false)
|
||||
{
|
||||
return rrd::line(1, $vname, $color, $text, $stack);
|
||||
}
|
||||
|
||||
public static function line2($vname = false, $color = false, $text = false, $stack = false)
|
||||
{
|
||||
return rrd::line(2, $vname, $color, $text, $stack);
|
||||
}
|
||||
|
||||
public static function line3($vname = false, $color = false, $text = false, $stack = false)
|
||||
{
|
||||
return rrd::line(3, $vname, $color, $text, $stack);
|
||||
}
|
||||
|
||||
public static function gprint($vname = false, $cf = "AVERAGE", $text = "%6.2lf %s")
|
||||
{
|
||||
$line = "";
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
|
||||
if (is_array($cf)) {
|
||||
foreach ($cf as $key => $val) {
|
||||
$line .= sprintf("GPRINT:%s:%s:", $vname, $val);
|
||||
if ($key == count($cf) - 1) {
|
||||
$line .= '"' . $text . ' ' . ucfirst(strtolower($val)) . '\\l" ';
|
||||
} else {
|
||||
$line .= '"' . $text . ' ' . ucfirst(strtolower($val)) . '" ';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$line .= sprintf("GPRINT:%s:%s:",$vname,$cf);
|
||||
$line .= '"'.$text.'" ';
|
||||
} else {
|
||||
$line .= sprintf("GPRINT:%s:%s:", $vname, $cf);
|
||||
$line .= '"' . $text . '" ';
|
||||
}
|
||||
return $line;
|
||||
return $line;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function to modify alignment of gprint
|
||||
*/
|
||||
public static function gprinta($vname=FALSE, $cf="AVERAGE", $text="%6.2lf %s", $align=""){
|
||||
/*
|
||||
* Function to modify alignment of gprint
|
||||
*/
|
||||
public static function gprinta($vname = false, $cf = "AVERAGE", $text = "%6.2lf %s", $align = "")
|
||||
{
|
||||
$line = "";
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if($align != ""){
|
||||
if ($align != "") {
|
||||
$align = '\\' . $align;
|
||||
}
|
||||
if(is_array($cf)){
|
||||
foreach($cf as $key => $val){
|
||||
$line .= sprintf("GPRINT:%s:%s:",$vname,$val);
|
||||
if(($key == sizeof($cf)-1)and($align != "")){
|
||||
$line .= '"'.$text.' '.ucfirst(strtolower($val)).$align.'" ';
|
||||
}else{
|
||||
$line .= '"'.$text.' '.ucfirst(strtolower($val)).'" ';
|
||||
if (is_array($cf)) {
|
||||
foreach ($cf as $key => $val) {
|
||||
$line .= sprintf("GPRINT:%s:%s:", $vname, $val);
|
||||
if (($key == count($cf) - 1) and ($align != "")) {
|
||||
$line .= '"' . $text . ' ' . ucfirst(strtolower($val)) . $align . '" ';
|
||||
} else {
|
||||
$line .= '"' . $text . ' ' . ucfirst(strtolower($val)) . '" ';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$line .= sprintf("GPRINT:%s:%s:",$vname,$cf);
|
||||
$line .= '"'.$text.'" ';
|
||||
} else {
|
||||
$line .= sprintf("GPRINT:%s:%s:", $vname, $cf);
|
||||
$line .= '"' . $text . '" ';
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function def($vname=FALSE, $rrdfile=FALSE, $ds=FALSE, $cf="AVERAGE"){
|
||||
public static function def($vname = false, $rrdfile = false, $ds = false, $cf = "AVERAGE")
|
||||
{
|
||||
$line = "";
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if($rrdfile === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'rrdfile' is missing");
|
||||
if ($rrdfile === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'rrdfile' is missing");
|
||||
}
|
||||
if($rrdfile === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Third Parameter 'ds' is missing");
|
||||
if ($rrdfile === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Third Parameter 'ds' is missing");
|
||||
}
|
||||
$line = sprintf("DEF:%s=%s:%s:%s ",$vname,$rrdfile,$ds,$cf);
|
||||
$line = sprintf("DEF:%s=%s:%s:%s ", $vname, $rrdfile, $ds, $cf);
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function cdef($vname=FALSE, $rpn=FALSE){
|
||||
public static function cdef($vname = false, $rpn = false)
|
||||
{
|
||||
$line = "";
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if($rpn === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'rpn' is missing");
|
||||
if ($rpn === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'rpn' is missing");
|
||||
}
|
||||
$line = sprintf("CDEF:%s=%s ",$vname,$rpn);
|
||||
$line = sprintf("CDEF:%s=%s ", $vname, $rpn);
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function vdef($vname=FALSE, $rpn=FALSE){
|
||||
public static function vdef($vname = false, $rpn = false)
|
||||
{
|
||||
$line = "";
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if($rpn === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'rpn' is missing");
|
||||
if ($rpn === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'rpn' is missing");
|
||||
}
|
||||
$line = sprintf("VDEF:%s=%s ",$vname,$rpn);
|
||||
$line = sprintf("VDEF:%s=%s ", $vname, $rpn);
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function hrule($value=FALSE, $color=FALSE, $text=FALSE){
|
||||
public static function hrule($value = false, $color = false, $text = false)
|
||||
{
|
||||
$line = "";
|
||||
if($value === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ ."() First Parameter 'value' is missing");
|
||||
if ($value === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'value' is missing");
|
||||
}
|
||||
if($color === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'color' is missing");
|
||||
if ($color === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'color' is missing");
|
||||
}
|
||||
if($value == "~" ) {
|
||||
return "";
|
||||
}
|
||||
$line = sprintf("HRULE:%s%s:\"%s\" ",$value,$color,$text);
|
||||
if ($value == "~") {
|
||||
return "";
|
||||
}
|
||||
$line = sprintf("HRULE:%s%s:\"%s\" ", $value, $color, $text);
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function comment($text=FALSE){
|
||||
|
||||
public static function comment($text = false)
|
||||
{
|
||||
$line = sprintf("COMMENT:\"%s\" ", $text);
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function tick($vname=FALSE, $color=FALSE, $fraction=FALSE, $label=FALSE){
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'value' is missing");
|
||||
public static function tick($vname = false, $color = false, $fraction = false, $label = false)
|
||||
{
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'value' is missing");
|
||||
}
|
||||
if($color === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'color' is missing");
|
||||
if ($color === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'color' is missing");
|
||||
}
|
||||
$line = sprintf("TICK:%s%s",$vname,$color);
|
||||
if($fraction != FALSE)
|
||||
$line = sprintf("TICK:%s%s", $vname, $color);
|
||||
if ($fraction != false) {
|
||||
$line .= ":$fraction";
|
||||
}
|
||||
|
||||
if($label != FALSE)
|
||||
if ($label != false) {
|
||||
$line .= ":$label";
|
||||
|
||||
}
|
||||
|
||||
$line .= " ";
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function alerter(
|
||||
$vname = false,
|
||||
$label = false,
|
||||
$warning = false,
|
||||
$critical = false,
|
||||
$opacity = 'ff',
|
||||
$unit = false,
|
||||
$color_green = '#00ff00',
|
||||
$color_btw = '#ffff00',
|
||||
$color_red = '#ff0000',
|
||||
$line_col = '#0000ff'
|
||||
) {
|
||||
|
||||
public static function alerter($vname=FALSE, $label=FALSE, $warning=FALSE, $critical=FALSE, $opacity = 'ff', $unit, $color_green = '#00ff00', $color_btw = '#ffff00', $color_red = '#ff0000', $line_col = '#0000ff') {
|
||||
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if($label === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'label' is missing");
|
||||
}
|
||||
if($warning === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Third Parameter 'warning' is missing");
|
||||
}
|
||||
if($critical === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Fourth Parameter 'critical' is missing");
|
||||
}
|
||||
$line = "";
|
||||
$green_vname = "var".substr(sha1(rand()),1,4);
|
||||
$btw_vname = "var".substr(sha1(rand()),1,4);
|
||||
$blue_vname = "var".substr(sha1(rand()),1,4);
|
||||
$red_vname = "var".substr(sha1(rand()),1,4);
|
||||
if($warning < $critical){
|
||||
$line .= "CDEF:".$green_vname."=".$vname.",".$warning.",LT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$btw_vname."=".$vname.",".$critical.",LT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$blue_vname."=".$btw_vname.",".$warning.",GE,".$btw_vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$red_vname."=".$vname.",".$critical.",GE,".$vname.",UNKN,IF ";
|
||||
} else {
|
||||
$line .= "CDEF:".$green_vname."=".$vname.",".$warning.",GT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$btw_vname."=".$vname.",".$critical.",GE,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$blue_vname."=".$btw_vname.",".$warning.",LE,".$btw_vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$red_vname."=".$vname.",".$critical.",LT,".$vname.",UNKN,IF ";
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
$line .= rrd::area($green_vname, $color_green.$opacity);
|
||||
$line .= rrd::area($blue_vname, $color_btw.$opacity);
|
||||
$line .= rrd::area($red_vname, $color_red.$opacity);
|
||||
$line .= rrd::line1($vname,$line_col,$label);
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function alerter_gr($vname=FALSE,$label=FALSE,$warning=FALSE,$critical=FALSE,$opacity='ff',$unit,$color_green='#00ff00',$color_btw='#ffff00',$color_red='#ff0000',$line_col='#0000ff',$start_color="#ffffff") {
|
||||
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
if ($label === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'label' is missing");
|
||||
}
|
||||
if($label === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'label' is missing");
|
||||
if ($warning === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Third Parameter 'warning' is missing");
|
||||
}
|
||||
if($warning === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Third Parameter 'warning' is missing");
|
||||
}
|
||||
if($critical === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Fourth Parameter 'critical' is missing");
|
||||
if ($critical === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Fourth Parameter 'critical' is missing");
|
||||
}
|
||||
$line = "";
|
||||
$green_vname = "var".substr(sha1(rand()),1,4);
|
||||
$btw_vname = "var".substr(sha1(rand()),1,4);
|
||||
$blue_vname = "var".substr(sha1(rand()),1,4);
|
||||
$red_vname = "var".substr(sha1(rand()),1,4);
|
||||
$line = "";
|
||||
if($warning < $critical){
|
||||
$line .= "CDEF:".$green_vname."=".$vname.",".$warning.",LT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$btw_vname."=".$vname.",".$critical.",LT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$blue_vname."=".$btw_vname.",".$warning.",GE,".$btw_vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$red_vname."=".$vname.",".$critical.",GE,".$vname.",UNKN,IF ";
|
||||
$green_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$btw_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$blue_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$red_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
if ($warning < $critical) {
|
||||
$line .= "CDEF:" . $green_vname . "=" . $vname . "," . $warning . ",LT," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $btw_vname . "=" . $vname . "," . $critical . ",LT," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $blue_vname . "=" . $btw_vname . "," . $warning . ",GE," . $btw_vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $red_vname . "=" . $vname . "," . $critical . ",GE," . $vname . ",UNKN,IF ";
|
||||
} else {
|
||||
$line .= "CDEF:".$green_vname."=".$vname.",".$warning.",GT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$btw_vname."=".$vname.",".$critical.",GE,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$blue_vname."=".$btw_vname.",".$warning.",LE,".$btw_vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$red_vname."=".$vname.",".$critical.",LT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:" . $green_vname . "=" . $vname . "," . $warning . ",GT," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $btw_vname . "=" . $vname . "," . $critical . ",GE," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $blue_vname . "=" . $btw_vname . "," . $warning . ",LE," . $btw_vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $red_vname . "=" . $vname . "," . $critical . ",LT," . $vname . ",UNKN,IF ";
|
||||
}
|
||||
$line .= rrd::gradient($green_vname, $start_color, $color_green.$opacity);
|
||||
$line .= rrd::gradient($blue_vname, $start_color, $color_btw.$opacity);
|
||||
$line .= rrd::gradient($red_vname, $start_color, $color_red.$opacity);
|
||||
$line .= rrd::line1($vname,$line_col,$label);
|
||||
$line .= rrd::area($green_vname, $color_green . $opacity);
|
||||
$line .= rrd::area($blue_vname, $color_btw . $opacity);
|
||||
$line .= rrd::area($red_vname, $color_red . $opacity);
|
||||
$line .= rrd::line1($vname, $line_col, $label);
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function ticker($vname=FALSE, $warning=FALSE, $critical=FALSE, $fraction = -0.05, $opacity = 'ff', $color_green = '#00ff00', $color_btw = '#ffff00', $color_red = '#ff0000') {
|
||||
|
||||
if($vname === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if($warning === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'warning' is missing");
|
||||
}
|
||||
if($critical === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Third Parameter 'critical' is missing");
|
||||
}
|
||||
$line = "";
|
||||
$green_vname = "var".substr(sha1(rand()),1,4);
|
||||
$btw_vname = "var".substr(sha1(rand()),1,4);
|
||||
$blue_vname = "var".substr(sha1(rand()),1,4);
|
||||
$red_vname = "var".substr(sha1(rand()),1,4);
|
||||
$green2_vname = "var".substr(sha1(rand()),1,4);
|
||||
$line .= "CDEF:".$green_vname."=".$vname.",".$warning.",LT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$btw_vname."=".$vname.",".$critical.",LT,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$blue_vname."=".$btw_vname.",".$warning.",GE,".$btw_vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$red_vname."=".$vname.",".$critical.",GE,".$vname.",UNKN,IF ";
|
||||
$line .= "CDEF:".$green2_vname."=".$green_vname.",0,EQ,0.000001,".$green_vname.",IF ";
|
||||
$line .= rrd::tick($green2_vname, $color_green.$opacity, $fraction);
|
||||
$line .= rrd::tick($blue_vname, $color_btw.$opacity, $fraction);
|
||||
$line .= rrd::tick($red_vname, $color_red.$opacity, $fraction);
|
||||
|
||||
return $line;
|
||||
public static function alerter_gr(
|
||||
$vname = false,
|
||||
$label = false,
|
||||
$warning = false,
|
||||
$critical = false,
|
||||
$opacity = 'ff',
|
||||
$unit = false,
|
||||
$color_green = '#00ff00',
|
||||
$color_btw = '#ffff00',
|
||||
$color_red = '#ff0000',
|
||||
$line_col = '#0000ff',
|
||||
$start_color = "#ffffff"
|
||||
) {
|
||||
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if ($label === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'label' is missing");
|
||||
}
|
||||
if ($warning === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Third Parameter 'warning' is missing");
|
||||
}
|
||||
if ($critical === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Fourth Parameter 'critical' is missing");
|
||||
}
|
||||
$line = "";
|
||||
$green_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$btw_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$blue_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$red_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$line = "";
|
||||
if ($warning < $critical) {
|
||||
$line .= "CDEF:" . $green_vname . "=" . $vname . "," . $warning . ",LT," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $btw_vname . "=" . $vname . "," . $critical . ",LT," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $blue_vname . "=" . $btw_vname . "," . $warning . ",GE," . $btw_vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $red_vname . "=" . $vname . "," . $critical . ",GE," . $vname . ",UNKN,IF ";
|
||||
} else {
|
||||
$line .= "CDEF:" . $green_vname . "=" . $vname . "," . $warning . ",GT," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $btw_vname . "=" . $vname . "," . $critical . ",GE," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $blue_vname . "=" . $btw_vname . "," . $warning . ",LE," . $btw_vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $red_vname . "=" . $vname . "," . $critical . ",LT," . $vname . ",UNKN,IF ";
|
||||
}
|
||||
$line .= rrd::gradient($green_vname, $start_color, $color_green . $opacity);
|
||||
$line .= rrd::gradient($blue_vname, $start_color, $color_btw . $opacity);
|
||||
$line .= rrd::gradient($red_vname, $start_color, $color_red . $opacity);
|
||||
$line .= rrd::line1($vname, $line_col, $label);
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function darkteint(){
|
||||
$line = '';
|
||||
$line .= '--color=BACK#000000 ';
|
||||
$line .= '--color=FONT#F7F7F7 ';
|
||||
$line .= '--color=SHADEA#ffffff ';
|
||||
$line .= '--color=SHADEB#ffffff ';
|
||||
$line .= '--color=CANVAS#000000 ';
|
||||
$line .= '--color=GRID#00991A ';
|
||||
$line .= '--color=MGRID#00991A ';
|
||||
$line .= '--color=ARROW#00FF00 ';
|
||||
public static function ticker(
|
||||
$vname = false,
|
||||
$warning = false,
|
||||
$critical = false,
|
||||
$fraction = -0.05,
|
||||
$opacity = 'ff',
|
||||
$color_green = '#00ff00',
|
||||
$color_btw = '#ffff00',
|
||||
$color_red = '#ff0000'
|
||||
) {
|
||||
|
||||
return $line;
|
||||
}
|
||||
if ($vname === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'vname' is missing");
|
||||
}
|
||||
if ($warning === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'warning' is missing");
|
||||
}
|
||||
if ($critical === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Third Parameter 'critical' is missing");
|
||||
}
|
||||
$line = "";
|
||||
$green_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$btw_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$blue_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$red_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$green2_vname = "var" . substr(sha1(rand()), 1, 4);
|
||||
$line .= "CDEF:" . $green_vname . "=" . $vname . "," . $warning . ",LT," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $btw_vname . "=" . $vname . "," . $critical . ",LT," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $blue_vname . "=" . $btw_vname . "," . $warning . ",GE," . $btw_vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $red_vname . "=" . $vname . "," . $critical . ",GE," . $vname . ",UNKN,IF ";
|
||||
$line .= "CDEF:" . $green2_vname . "=" . $green_vname . ",0,EQ,0.000001," . $green_vname . ",IF ";
|
||||
$line .= rrd::tick($green2_vname, $color_green . $opacity, $fraction);
|
||||
$line .= rrd::tick($blue_vname, $color_btw . $opacity, $fraction);
|
||||
$line .= rrd::tick($red_vname, $color_red . $opacity, $fraction);
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function darkteint()
|
||||
{
|
||||
$line = '';
|
||||
$line .= '--color=BACK#000000 ';
|
||||
$line .= '--color=FONT#F7F7F7 ';
|
||||
$line .= '--color=SHADEA#ffffff ';
|
||||
$line .= '--color=SHADEB#ffffff ';
|
||||
$line .= '--color=CANVAS#000000 ';
|
||||
$line .= '--color=GRID#00991A ';
|
||||
$line .= '--color=MGRID#00991A ';
|
||||
$line .= '--color=ARROW#00FF00 ';
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
# http://stackoverflow.com/questions/3512311/how-to-generate-lighter-darker-color-with-php
|
||||
public static function colbright($hex, $steps) {
|
||||
if($hex === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() First Parameter 'hex' is missing");
|
||||
public static function colbright($hex, $steps)
|
||||
{
|
||||
if ($hex === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() First Parameter 'hex' is missing");
|
||||
}
|
||||
if($steps === FALSE){
|
||||
throw new Kohana_exception("rrd::". __FUNCTION__ . "() Second Parameter 'steps' is missing");
|
||||
if ($steps === false) {
|
||||
throw new Kohana_exception("rrd::" . __FUNCTION__ . "() Second Parameter 'steps' is missing");
|
||||
}
|
||||
// Steps should be between -255 and 255. Negative = darker, positive = lighter
|
||||
$steps = max(-255, min(255, $steps));
|
||||
@@ -458,7 +521,7 @@ class rrd_Core {
|
||||
// Normalize into a six character long hex string
|
||||
$hex = str_replace('#', '', $hex);
|
||||
if (strlen($hex) == 3) {
|
||||
$hex = str_repeat(substr($hex,0,1), 2).str_repeat(substr($hex,1,1), 2).str_repeat(substr($hex,2,1), 2);
|
||||
$hex = str_repeat(substr($hex, 0, 1), 2) . str_repeat(substr($hex, 1, 1), 2) . str_repeat(substr($hex, 2, 1), 2);
|
||||
}
|
||||
|
||||
// Split into three parts: R, G and B
|
||||
@@ -467,22 +530,22 @@ class rrd_Core {
|
||||
|
||||
foreach ($color_parts as $color) {
|
||||
$color = hexdec($color); // Convert to decimal
|
||||
$color = max(0,min(255,$color + $steps)); // Adjust color
|
||||
$color = max(0, min(255, $color + $steps)); // Adjust color
|
||||
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public static function debug($data=FALSE){
|
||||
if($data != FALSE){
|
||||
ob_start();
|
||||
public static function debug($data = false)
|
||||
{
|
||||
if ($data != false) {
|
||||
ob_start();
|
||||
|
||||
var_dump($data);
|
||||
var_dump($data);
|
||||
$var_dump = ob_get_contents();
|
||||
$var_dump = preg_replace('/(HRULE|VDEF|DEF|CDEF|GPRINT|LINE|AREA|COMMENT)/',"\n\${1}", $var_dump);
|
||||
ob_end_clean();
|
||||
throw new Kohana_exception("<pre>".$var_dump."</pre>");
|
||||
}
|
||||
$var_dump = preg_replace('/(HRULE|VDEF|DEF|CDEF|GPRINT|LINE|AREA|COMMENT)/', "\n\${1}", $var_dump);
|
||||
ob_end_clean();
|
||||
throw new Kohana_exception("<pre>" . $var_dump . "</pre>");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user