Imported Upstream version 0.6.24+dfsg1
This commit is contained in:
58
share/pnp/application/helpers/nagios.php
Normal file
58
share/pnp/application/helpers/nagios.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
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);
|
||||
$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";
|
||||
}
|
||||
|
||||
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);
|
||||
$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\"";
|
||||
|
||||
}
|
||||
print " title=\"".Kohana::lang('common.nagios-avail-link-title')."\"><img src=\"".url::base()."media/images/trends.gif\" ></a>\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
150
share/pnp/application/helpers/pnp.php
Normal file
150
share/pnp/application/helpers/pnp.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
class pnp_Core {
|
||||
|
||||
public static function clean($string = FALSE){
|
||||
if($string === FALSE){
|
||||
return;
|
||||
}
|
||||
if($string == ""){
|
||||
return $string;
|
||||
}
|
||||
$string = preg_replace('/[ :\/\\\]/', "_", $string);
|
||||
$string = htmlspecialchars($string);
|
||||
return $string;
|
||||
|
||||
}
|
||||
public static function shorten($string = FALSE, $length = 25){
|
||||
if($string === FALSE){
|
||||
return;
|
||||
}
|
||||
if(strlen($string) > $length){
|
||||
$string = substr($string, 0, $length) . "...";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static function xml_version_check($string = FALSE){
|
||||
if($string === FALSE){
|
||||
return FALSE;
|
||||
}
|
||||
if( $string == XML_STRUCTURE_VERSION ){
|
||||
$string = "valid";
|
||||
}else{
|
||||
$string = Kohana::lang('error.xml-structure-mismatch', $string, XML_STRUCTURE_VERSION);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static function zoom_icon($host,$service,$start,$end,$source,$view,$graph_width,$graph_height){
|
||||
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 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));
|
||||
return $link;
|
||||
}
|
||||
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)){
|
||||
return false;
|
||||
}
|
||||
$get = $_GET;
|
||||
if($base === True){
|
||||
$uri = url::base(TRUE);
|
||||
$uri .= Router::$current_uri;
|
||||
}else{
|
||||
$uri = "";
|
||||
}
|
||||
$uri .= '?';
|
||||
foreach($fields as $key=>$value){
|
||||
$get[$key] = $value;
|
||||
}
|
||||
foreach($get as $key=>$value){
|
||||
if($value === ''){
|
||||
continue;
|
||||
}
|
||||
$uri .= $key."=".urlencode($value)."&";
|
||||
}
|
||||
return rtrim($uri,"&");
|
||||
}
|
||||
|
||||
/* "normalize" and adjust value / unit (similar to format string %s in RRDtool)
|
||||
* Parameters in:
|
||||
* value := number, maybe suffixed by unit string
|
||||
* examples: 1234, 1.234, 1234M, 1234Kb
|
||||
* base := base of value (1000, e.g. traffic or 1024, e.g. disk size)
|
||||
* format := format string
|
||||
* Parameters out:
|
||||
* val_unit := formatted value (including unit)
|
||||
* val_fmt := formatted value (without leading blanks and unit)
|
||||
* 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);
|
||||
|
||||
$mag = 0;
|
||||
while ($value >= $base){
|
||||
$value /= $base;
|
||||
$mag++;
|
||||
}
|
||||
$pos = 0;
|
||||
if ($matches[2] == "%") {
|
||||
$unit = '%';
|
||||
} else {
|
||||
if ($matches[2] == "") {
|
||||
$matches[2] = " ";
|
||||
}
|
||||
if (($matches[2] == "B") or ($matches[2] == "b")) {
|
||||
$matches[3] = $matches[2];
|
||||
$matches[2] = " ";
|
||||
}
|
||||
$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));
|
||||
}
|
||||
|
||||
public static function print_version(){
|
||||
return PNP_NAME . "-" . PNP_VERSION . " [ " . PNP_REL_DATE . " ]";
|
||||
}
|
||||
|
||||
}
|
||||
459
share/pnp/application/helpers/rrd.php
Normal file
459
share/pnp/application/helpers/rrd.php
Normal file
@@ -0,0 +1,459 @@
|
||||
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
||||
/*
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
# 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];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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");
|
||||
}
|
||||
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."'");
|
||||
}
|
||||
|
||||
$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."'");
|
||||
|
||||
$lower = $matches[1];
|
||||
$spline .= sprintf("CDEF:%sminimum=%s,100,/,%d,* ", $vname, $vname, $lower);
|
||||
}elseif(preg_match('/^([0-9]+)$/', $lower, $matches)){
|
||||
$lower = $matches[1];
|
||||
$spline .= sprintf("CDEF:%sminimum=%s,%d,- ", $vname, $vname, $lower);
|
||||
}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 );
|
||||
# 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);
|
||||
}
|
||||
}
|
||||
return $spline;
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
}
|
||||
$s = sprintf($format,$string);
|
||||
return $s;
|
||||
}
|
||||
|
||||
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($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){
|
||||
$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 == sizeof($cf)-1){
|
||||
$line .= '"'.$text.' '.ucfirst(strtolower($val)).'\\l" ';
|
||||
}else{
|
||||
$line .= '"'.$text.' '.ucfirst(strtolower($val)).'" ';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$line .= sprintf("GPRINT:%s:%s:",$vname,$cf);
|
||||
$line .= '"'.$text.'" ';
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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($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)).'" ';
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$line .= sprintf("GPRINT:%s:%s:",$vname,$cf);
|
||||
$line .= '"'.$text.'" ';
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
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($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");
|
||||
}
|
||||
$line = sprintf("DEF:%s=%s:%s:%s ",$vname,$rrdfile,$ds,$cf);
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function cdef($vname=FALSE, $rpn=FALSE){
|
||||
$line = "";
|
||||
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");
|
||||
}
|
||||
$line = sprintf("CDEF:%s=%s ",$vname,$rpn);
|
||||
return $line;
|
||||
}
|
||||
|
||||
public static function vdef($vname=FALSE, $rpn=FALSE){
|
||||
$line = "";
|
||||
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");
|
||||
}
|
||||
$line = sprintf("VDEF:%s=%s ",$vname,$rpn);
|
||||
return $line;
|
||||
}
|
||||
|
||||
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($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);
|
||||
return $line;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
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 .= ":$fraction";
|
||||
|
||||
if($label != FALSE)
|
||||
$line .= ":$label";
|
||||
|
||||
$line .= " ";
|
||||
return $line;
|
||||
}
|
||||
|
||||
|
||||
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 ";
|
||||
}
|
||||
$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($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 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 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;
|
||||
}
|
||||
|
||||
public static function debug($data=FALSE){
|
||||
if($data != FALSE){
|
||||
ob_start();
|
||||
|
||||
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>");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user