2016-10-05 14:30:55 +01:00
#
# Monitorix - A lightweight system monitoring tool.
#
2019-03-14 14:41:20 +00:00
# Copyright (C) 2005-2019 by Jordi Sanfeliu <jordi@fibranet.cat>
2016-10-05 14:30:55 +01:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
package gensens ;
use strict ;
use warnings ;
use Monitorix ;
use RRDs ;
use POSIX qw( strftime ) ;
use Exporter 'import' ;
our @ EXPORT = qw( gensens_init gensens_update gensens_cgi ) ;
sub gensens_init {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ gensens = $ config - > { gensens } ;
my $ info ;
2019-05-02 14:46:57 +01:00
my @ ds ;
2016-10-05 14:30:55 +01:00
my @ rra ;
my @ tmp ;
my $ n ;
my @ average ;
my @ min ;
my @ max ;
my @ last ;
if ( - e $ rrd ) {
$ info = RRDs:: info ( $ rrd ) ;
for my $ key ( keys %$ info ) {
2019-05-02 14:46:57 +01:00
if ( index ( $ key , 'ds[' ) == 0 ) {
if ( index ( $ key , '.type' ) != - 1 ) {
push ( @ ds , substr ( $ key , 3 , index ( $ key , ']' ) - 3 ) ) ;
}
}
2016-10-05 14:30:55 +01:00
if ( index ( $ key , 'rra[' ) == 0 ) {
if ( index ( $ key , '.rows' ) != - 1 ) {
push ( @ rra , substr ( $ key , 4 , index ( $ key , ']' ) - 4 ) ) ;
}
}
}
2019-05-02 14:46:57 +01:00
if ( scalar ( @ ds ) / 9 != keys % { $ gensens - > { list } } ) {
logger ( "$myself: Detected size mismatch between 'list' (" . keys ( % { $ gensens - > { list } } ) . ") and $rrd (" . scalar ( @ ds ) / 9 . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
rename ( $ rrd , "$rrd.bak" ) ;
}
2016-10-05 14:30:55 +01:00
if ( scalar ( @ rra ) < 12 + ( 4 * $ config - > { max_historic_years } ) ) {
logger ( "$myself: Detected size mismatch between 'max_historic_years' (" . $ config - > { max_historic_years } . ") and $rrd (" . ( ( scalar ( @ rra ) - 12 ) / 4 ) . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
rename ( $ rrd , "$rrd.bak" ) ;
}
}
if ( ! ( - e $ rrd ) ) {
logger ( "Creating '$rrd' file." ) ;
for ( $ n = 1 ; $ n <= $ config - > { max_historic_years } ; $ n + + ) {
push ( @ average , "RRA:AVERAGE:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ min , "RRA:MIN:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ max , "RRA:MAX:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ last , "RRA:LAST:0.5:1440:" . ( 365 * $ n ) ) ;
}
2019-05-02 14:46:57 +01:00
for ( $ n = 0 ; $ n < keys % { $ gensens - > { list } } ; $ n + + ) {
push ( @ tmp , "DS:gensens" . $ n . "_s1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:gensens" . $ n . "_s2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:gensens" . $ n . "_s3:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:gensens" . $ n . "_s4:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:gensens" . $ n . "_s5:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:gensens" . $ n . "_s6:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:gensens" . $ n . "_s7:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:gensens" . $ n . "_s8:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:gensens" . $ n . "_s9:GAUGE:120:0:U" )
}
2016-10-05 14:30:55 +01:00
eval {
RRDs:: create ( $ rrd ,
"--step=60" ,
2019-05-02 14:46:57 +01:00
@ tmp ,
2016-10-05 14:30:55 +01:00
"RRA:AVERAGE:0.5:1:1440" ,
"RRA:AVERAGE:0.5:30:336" ,
"RRA:AVERAGE:0.5:60:744" ,
@ average ,
"RRA:MIN:0.5:1:1440" ,
"RRA:MIN:0.5:30:336" ,
"RRA:MIN:0.5:60:744" ,
@ min ,
"RRA:MAX:0.5:1:1440" ,
"RRA:MAX:0.5:30:336" ,
"RRA:MAX:0.5:60:744" ,
@ max ,
"RRA:LAST:0.5:1:1440" ,
"RRA:LAST:0.5:30:336" ,
"RRA:LAST:0.5:60:744" ,
@ last ,
) ;
} ;
my $ err = RRDs:: error ;
if ( $@ || $ err ) {
logger ( "$@" ) unless ! $@ ;
if ( $ err ) {
logger ( "ERROR: while creating $rrd: $err" ) ;
if ( $ err eq "RRDs::error" ) {
logger ( "... is the RRDtool Perl package installed?" ) ;
}
}
return ;
}
}
2017-07-26 11:22:08 +01:00
$ config - > { gensens_hist_alerts } = ( ) ;
2016-10-05 14:30:55 +01:00
push ( @ { $ config - > { func_update } } , $ package ) ;
logger ( "$myself: Ok" ) if $ debug ;
}
sub gensens_update {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ gensens = $ config - > { gensens } ;
my $ n ;
my $ rrdata = "N" ;
foreach my $ sg ( sort keys % { $ gensens - > { list } } ) {
my @ ls = split ( ',' , $ gensens - > { list } - > { $ sg } ) ;
for ( $ n = 0 ; $ n < 9 ; $ n + + ) {
my $ val ;
my $ str ;
$ val = 0 ;
$ str = trim ( $ ls [ $ n ] || "" ) ;
if ( $ gensens - > { desc } - > { $ str } ) {
if ( open ( IN , $ gensens - > { desc } - > { $ str } ) ) {
my $ unit ;
2016-10-05 17:21:52 +01:00
my $ c ;
2016-10-05 14:30:55 +01:00
$ val = <IN> ;
$ val = trim ( $ val ) ;
$ unit = $ gensens - > { unit } - > { $ str } || 0 ;
2016-10-05 17:21:52 +01:00
$ c = ( ) = $ unit =~ /0/g ;
$ val /= 10 ** $ c if $ unit > 1 ;
$ val *= 10 ** $ c if $ unit > 0 && $ unit < 1 ;
2016-10-05 14:30:55 +01:00
close ( IN ) ;
} else {
logger ( "$myself: ERROR: unable to open '$gensens->{desc}->{$str}'." ) ;
}
}
2017-07-26 11:22:08 +01:00
# check alerts for each sensor defined
my @ al = split ( ',' , $ gensens - > { alerts } - > { $ str } || "" ) ;
if ( scalar ( @ al ) ) {
my $ timeintvl = trim ( $ al [ 0 ] ) ;
my $ threshold = trim ( $ al [ 1 ] ) ;
my $ script = trim ( $ al [ 2 ] ) ;
2019-02-08 08:45:12 +00:00
my $ when = lc ( trim ( $ al [ 3 ] || "" ) ) ;
my @ range = split ( '-' , $ threshold ) ;
$ threshold = 0 if ! $ threshold ;
if ( scalar ( @ range ) == 1 ) {
2019-04-23 15:15:48 +01:00
$ when = "above" if ! $ when ; # 'above' is the default
2019-02-08 08:45:12 +00:00
if ( $ when eq "above" && $ val < $ threshold ) {
$ config - > { gensens_hist_alerts } - > { $ str } = 0 ;
} elsif ( $ when eq "below" && $ val > $ threshold ) {
$ config - > { gensens_hist_alerts } - > { $ str } = 0 ;
} else {
if ( $ when eq "above" || $ when eq "below" ) {
if ( ! $ config - > { gensens_hist_alerts } - > { $ str } ) {
$ config - > { gensens_hist_alerts } - > { $ str } = time ;
}
if ( $ config - > { gensens_hist_alerts } - > { $ str } > 0 && ( time - $ config - > { gensens_hist_alerts } - > { $ str } ) >= $ timeintvl ) {
if ( - x $ script ) {
logger ( "$myself: alert on Generic Sensor ($str): executing script '$script'." ) ;
system ( $ script . " " . $ timeintvl . " " . $ threshold . " " . $ val . " " . $ when ) ;
} else {
logger ( "$myself: ERROR: script '$script' doesn't exist or don't has execution permissions." ) ;
}
$ config - > { gensens_hist_alerts } - > { $ str } = time ;
}
2017-07-26 11:22:08 +01:00
} else {
2019-02-08 08:45:12 +00:00
logger ( "$myself: ERROR: invalid when value '$when'" ) ;
2017-07-26 11:22:08 +01:00
}
}
2019-02-08 08:45:12 +00:00
} elsif ( scalar ( @ range ) == 2 ) {
2019-04-23 14:41:35 +01:00
if ( $ when ) {
logger ( "$myself: the forth parameter ('$when') in '$str' is irrelevant when there are range values defined." ) ;
}
if ( $ range [ 0 ] == $ range [ 1 ] ) {
logger ( "$myself: ERROR: range values are identical." ) ;
} else {
if ( $ val <= $ range [ 0 ] ) {
$ config - > { gensens_hist_alerts } - > { $ str } - > { above } = 0 ;
if ( $ val < $ range [ 0 ] && ! $ config - > { gensens_hist_alerts } - > { $ str } - > { below } ) {
$ config - > { gensens_hist_alerts } - > { $ str } - > { below } = time ;
}
}
if ( $ val >= $ range [ 1 ] ) {
$ config - > { gensens_hist_alerts } - > { $ str } - > { below } = 0 ;
if ( $ val > $ range [ 1 ] && ! $ config - > { gensens_hist_alerts } - > { $ str } - > { above } ) {
$ config - > { gensens_hist_alerts } - > { $ str } - > { above } = time ;
}
}
if ( $ config - > { gensens_hist_alerts } - > { $ str } - > { below } > 0 && ( time - $ config - > { gensens_hist_alerts } - > { $ str } - > { below } ) >= $ timeintvl ) {
if ( - x $ script ) {
logger ( "$myself: alert on Generic Sensor ($str): executing script '$script'." ) ;
system ( $ script . " " . $ timeintvl . " " . $ threshold . " " . $ val ) ;
} else {
logger ( "$myself: ERROR: script '$script' doesn't exist or don't has execution permissions." ) ;
}
$ config - > { gensens_hist_alerts } - > { $ str } - > { below } = time ;
}
if ( $ config - > { gensens_hist_alerts } - > { $ str } - > { above } > 0 && ( time - $ config - > { gensens_hist_alerts } - > { $ str } - > { above } ) >= $ timeintvl ) {
if ( - x $ script ) {
logger ( "$myself: alert on Generic Sensor ($str): executing script '$script'." ) ;
system ( $ script . " " . $ timeintvl . " " . $ threshold . " " . $ val ) ;
} else {
logger ( "$myself: ERROR: script '$script' doesn't exist or don't has execution permissions." ) ;
}
$ config - > { gensens_hist_alerts } - > { $ str } - > { above } = time ;
}
}
2019-02-08 08:45:12 +00:00
} else {
logger ( "$myself: ERROR: invalid threshold value '$threshold'" ) ;
2017-07-26 11:22:08 +01:00
}
}
2016-10-05 14:30:55 +01:00
$ rrdata . = ":$val" ;
}
}
RRDs:: update ( $ rrd , $ rrdata ) ;
logger ( "$myself: $rrdata" ) if $ debug ;
my $ err = RRDs:: error ;
logger ( "ERROR: while updating $rrd: $err" ) if $ err ;
}
sub gensens_cgi {
my ( $ package , $ config , $ cgi ) = @ _ ;
2017-07-26 10:26:12 +01:00
my @ output ;
2016-10-05 14:30:55 +01:00
my $ gensens = $ config - > { gensens } ;
my @ rigid = split ( ',' , ( $ gensens - > { rigid } || "" ) ) ;
my @ limit = split ( ',' , ( $ gensens - > { limit } || "" ) ) ;
my $ tf = $ cgi - > { tf } ;
my $ colors = $ cgi - > { colors } ;
my $ graph = $ cgi - > { graph } ;
my $ silent = $ cgi - > { silent } ;
my $ zoom = "--zoom=" . $ config - > { global_zoom } ;
my % rrd = (
'new' = > \ & RRDs:: graphv ,
'old' = > \ & RRDs:: graph ,
) ;
my $ version = "new" ;
my $ pic ;
my $ picz ;
my $ picz_width ;
my $ picz_height ;
my $ u = "" ;
my $ width ;
my $ height ;
2019-05-08 11:54:03 +01:00
my @ extra ;
2016-10-05 14:30:55 +01:00
my @ riglim ;
my $ temp_scale = "Celsius" ;
my @ IMG ;
my @ IMGz ;
my @ tmp ;
my @ tmpz ;
my @ CDEF ;
my $ n ;
my $ n2 ;
my $ str ;
my $ err ;
my @ LC = (
"#EEEE44" ,
2016-10-14 07:51:58 +01:00
"#4444EE" ,
2016-10-05 14:30:55 +01:00
"#44EEEE" ,
"#EE44EE" ,
"#888888" ,
"#E29136" ,
"#44EE44" ,
"#448844" ,
"#EE4444" ,
) ;
$ version = "old" if $ RRDs:: VERSION < 1.3 ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ title = $ config - > { graph_title } - > { $ package } ;
my $ IMG_DIR = $ config - > { base_dir } . "/" . $ config - > { imgs_dir } ;
my $ imgfmt_uc = uc ( $ config - > { image_format } ) ;
my $ imgfmt_lc = lc ( $ config - > { image_format } ) ;
2019-05-08 11:54:03 +01:00
foreach my $ i ( split ( ',' , $ config - > { rrdtool_extra_options } || "" ) ) {
push ( @ extra , trim ( $ i ) ) if trim ( $ i ) ;
}
2016-10-05 14:30:55 +01:00
$ title = ! $ silent ? $ title : "" ;
if ( lc ( $ config - > { temperature_scale } ) eq "f" ) {
$ temp_scale = "Fahrenheit" ;
}
# text mode
#
if ( lc ( $ config - > { iface_mode } ) eq "text" ) {
if ( $ title ) {
2017-07-26 10:26:12 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2016-10-05 14:30:55 +01:00
}
my ( undef , undef , undef , $ data ) = RRDs:: fetch ( "$rrd" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
"AVERAGE" ,
"-r $tf->{res}" ) ;
$ err = RRDs:: error ;
2017-07-26 10:26:12 +01:00
push ( @ output , "ERROR: while fetching $rrd: $err\n" ) if $ err ;
2016-10-05 14:30:55 +01:00
my $ line1 ;
my $ line2 ;
my $ line3 ;
2017-07-26 10:26:12 +01:00
push ( @ output , " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n" ) ;
push ( @ output , " " ) ;
2019-05-02 14:46:57 +01:00
foreach my $ sg ( sort keys % { $ gensens - > { list } } ) {
2016-10-05 14:30:55 +01:00
$ line1 = "" ;
2019-05-02 14:46:57 +01:00
foreach my $ i ( split ( ',' , $ gensens - > { list } - > { $ sg } ) ) {
2016-10-05 14:30:55 +01:00
$ i = trim ( $ i ) ;
$ str = $ i ;
2019-05-02 14:46:57 +01:00
$ str = sprintf ( "%12s" , substr ( $ str , 0 , 10 ) ) ;
$ line1 . = " " ;
$ line2 . = sprintf ( " %12s" , $ str ) ;
$ line3 . = "-------------" ;
2016-10-05 14:30:55 +01:00
}
if ( $ line1 ) {
my $ i = length ( $ line1 ) ;
2019-05-02 14:46:57 +01:00
push ( @ output , substr ( sprintf ( "%${i}s" , sprintf ( "%s" , trim ( $ gensens - > { title } - > { $ sg } ) ) ) , 0 , 13 ) ) ;
2016-10-05 14:30:55 +01:00
}
}
2017-07-26 10:26:12 +01:00
push ( @ output , "\n" ) ;
push ( @ output , "Time$line2\n" ) ;
push ( @ output , "----$line3 \n" ) ;
2016-10-05 14:30:55 +01:00
my $ line ;
my @ row ;
my $ time ;
my $ n2 ;
my $ from ;
my $ to ;
for ( $ n = 0 , $ time = $ tf - > { tb } ; $ n < ( $ tf - > { tb } * $ tf - > { ts } ) ; $ n + + ) {
$ line = @$ data [ $ n ] ;
$ time = $ time - ( 1 / $ tf - > { ts } ) ;
2017-07-26 10:26:12 +01:00
push ( @ output , sprintf ( " %2d$tf->{tc} " , $ time ) ) ;
2019-05-02 14:46:57 +01:00
foreach my $ sg ( sort keys % { $ gensens - > { list } } ) {
$ n2 = 0 ;
foreach my $ i ( split ( ',' , $ gensens - > { list } - > { $ sg } ) ) {
$ from = $ sg * 9 + $ n2 + + ;
2016-10-05 14:30:55 +01:00
$ to = $ from + 1 ;
my ( $ j ) = @$ line [ $ from .. $ to ] ;
2019-05-02 14:46:57 +01:00
@ row = ( $ j || 0 ) ;
push ( @ output , sprintf ( "%12d " , @ row ) ) ;
2016-10-05 14:30:55 +01:00
}
2019-05-02 14:46:57 +01:00
$ n2 + + ;
2016-10-05 14:30:55 +01:00
}
2017-07-26 10:26:12 +01:00
push ( @ output , "\n" ) ;
2016-10-05 14:30:55 +01:00
}
2017-07-26 10:26:12 +01:00
push ( @ output , " </pre>\n" ) ;
2016-10-05 14:30:55 +01:00
if ( $ title ) {
2017-07-26 10:26:12 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2016-10-05 14:30:55 +01:00
}
2017-07-26 10:26:12 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2016-10-05 14:30:55 +01:00
}
# graph mode
#
if ( $ silent eq "yes" || $ silent eq "imagetag" ) {
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "_" ;
}
if ( $ silent eq "imagetagbig" ) {
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "" ;
}
for ( $ n = 0 ; $ n < keys ( % { $ gensens - > { list } } ) ; $ n + + ) {
$ str = $ u . $ package . $ n . "." . $ tf - > { when } . ".$imgfmt_lc" ;
push ( @ IMG , $ str ) ;
unlink ( "$IMG_DIR" . $ str ) ;
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
$ str = $ u . $ package . $ n . "z." . $ tf - > { when } . ".$imgfmt_lc" ;
push ( @ IMGz , $ str ) ;
unlink ( "$IMG_DIR" . $ str ) ;
}
}
2019-05-02 14:46:57 +01:00
my @ linpad = ( 0 ) ;
my $ e = 0 ;
foreach my $ sg ( sort keys % { $ gensens - > { list } } ) {
my @ ls = split ( ',' , $ gensens - > { list } - > { $ sg } ) ;
$ linpad [ $ e ] = scalar ( @ ls ) ;
if ( $ e && $ e % 2 ) {
$ linpad [ $ e ] = max ( $ linpad [ $ e - 1 ] , $ linpad [ $ e ] ) ;
$ linpad [ $ e - 1 ] = $ linpad [ $ e ] ;
}
$ e + + ;
2016-10-05 14:30:55 +01:00
}
2019-05-02 14:46:57 +01:00
my $ vlabel ;
$ e = 0 ;
foreach my $ sg ( sort keys % { $ gensens - > { list } } ) {
my @ ls = split ( ',' , $ gensens - > { list } - > { $ sg } ) ;
# determine if we are dealing with a 'temp', 'cpu' or 'bat' graph
if ( index ( $ ls [ 0 ] , "temp" ) == 0 ) {
$ vlabel = $ temp_scale ;
} elsif ( index ( $ ls [ 0 ] , "cpu" ) == 0 ) {
$ vlabel = "Hz" ;
} elsif ( index ( $ ls [ 0 ] , "bat" ) == 0 ) {
$ vlabel = "Charge" ;
} else {
# not supported yet
2016-10-05 14:30:55 +01:00
}
2019-05-02 14:46:57 +01:00
if ( ! $ e ) {
if ( $ title ) {
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
push ( @ output , " <tr>\n" ) ;
2016-10-05 14:30:55 +01:00
}
}
2019-05-02 14:46:57 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ $ e ] , $ limit [ $ e ] ) } ;
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
for ( $ n = 0 ; $ n < 9 ; $ n + + ) {
my $ str = trim ( $ ls [ $ n ] || "" ) ;
if ( $ str ) {
$ str = $ gensens - > { map } - > { $ str } ? $ gensens - > { map } - > { $ str } : $ str ;
$ str = sprintf ( "%-20s" , substr ( $ str , 0 , 20 ) ) ;
push ( @ tmp , "LINE2:gsen" . $ n . $ LC [ $ n ] . ":$str" ) ;
push ( @ tmp , "GPRINT:gsen" . $ n . ":LAST: Cur\\:%5.1lf%s" ) ;
push ( @ tmp , "GPRINT:gsen" . $ n . ":MIN: Min\\:%5.1lf%s" ) ;
push ( @ tmp , "GPRINT:gsen" . $ n . ":MAX: Max\\:%5.1lf%s\\n" ) ;
push ( @ tmpz , "LINE2:gsen" . $ n . $ LC [ $ n ] . ":$str" ) ;
next ;
}
last ;
}
while ( $ n < $ linpad [ $ e ] ) {
push ( @ tmp , "COMMENT: \\n" ) ;
$ n + + ;
}
2016-10-05 14:30:55 +01:00
2019-05-02 14:46:57 +01:00
if ( $ title ) {
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2016-10-05 14:30:55 +01:00
}
2019-05-02 14:46:57 +01:00
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ tmpz , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { medium } ) ;
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e]" ,
"--title=$gensens->{title}->{$sg} ($tf->{nwhen}$tf->{twhen})" ,
2016-10-05 14:30:55 +01:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
"--imgformat=$imgfmt_uc" ,
2019-05-02 14:46:57 +01:00
"--vertical-label=$vlabel" ,
2016-10-05 14:30:55 +01:00
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2016-10-05 14:30:55 +01:00
@ riglim ,
$ zoom ,
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
2019-05-02 14:46:57 +01:00
"DEF:gsen0=$rrd:gensens" . $ e . "_s1:AVERAGE" ,
"DEF:gsen1=$rrd:gensens" . $ e . "_s2:AVERAGE" ,
"DEF:gsen2=$rrd:gensens" . $ e . "_s3:AVERAGE" ,
"DEF:gsen3=$rrd:gensens" . $ e . "_s4:AVERAGE" ,
"DEF:gsen4=$rrd:gensens" . $ e . "_s5:AVERAGE" ,
"DEF:gsen5=$rrd:gensens" . $ e . "_s6:AVERAGE" ,
"DEF:gsen6=$rrd:gensens" . $ e . "_s7:AVERAGE" ,
"DEF:gsen7=$rrd:gensens" . $ e . "_s8:AVERAGE" ,
"DEF:gsen8=$rrd:gensens" . $ e . "_s9:AVERAGE" ,
2017-10-30 09:01:12 +00:00
"CDEF:allvalues=gsen0,gsen1,gsen2,gsen3,gsen4,gsen5,gsen6,gsen7,gsen8,+,+,+,+,+,+,+,+" ,
2016-10-05 14:30:55 +01:00
@ CDEF ,
2019-05-02 14:46:57 +01:00
@ tmp ) ;
2016-10-05 14:30:55 +01:00
$ err = RRDs:: error ;
2019-05-02 14:46:57 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e]: $err\n" ) if $ err ;
2016-10-05 14:30:55 +01:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
2019-05-02 14:46:57 +01:00
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMGz[$e]" ,
"--title=$gensens->{title}->{$sg} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
"--imgformat=$imgfmt_uc" ,
"--vertical-label=$vlabel" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2019-05-02 14:46:57 +01:00
@ riglim ,
$ zoom ,
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:gsen0=$rrd:gensens" . $ e . "_s1:AVERAGE" ,
"DEF:gsen1=$rrd:gensens" . $ e . "_s2:AVERAGE" ,
"DEF:gsen2=$rrd:gensens" . $ e . "_s3:AVERAGE" ,
"DEF:gsen3=$rrd:gensens" . $ e . "_s4:AVERAGE" ,
"DEF:gsen4=$rrd:gensens" . $ e . "_s5:AVERAGE" ,
"DEF:gsen5=$rrd:gensens" . $ e . "_s6:AVERAGE" ,
"DEF:gsen6=$rrd:gensens" . $ e . "_s7:AVERAGE" ,
"DEF:gsen7=$rrd:gensens" . $ e . "_s8:AVERAGE" ,
"DEF:gsen8=$rrd:gensens" . $ e . "_s9:AVERAGE" ,
"CDEF:allvalues=gsen0,gsen1,gsen2,gsen3,gsen4,gsen5,gsen6,gsen7,gsen8,+,+,+,+,+,+,+,+" ,
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e]: $err\n" ) if $ err ;
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /gensens0/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e ] . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e ] . "' border='0'></a>\n" ) ;
2016-10-05 14:30:55 +01:00
} else {
2019-05-02 14:46:57 +01:00
if ( $ version eq "new" ) {
$ picz_width = $ picz - > { image_width } * $ config - > { global_zoom } ;
$ picz_height = $ picz - > { image_height } * $ config - > { global_zoom } ;
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e ] . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e ] . "' border='0'></a>\n" ) ;
2016-10-05 14:30:55 +01:00
}
2019-05-02 14:46:57 +01:00
} else {
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e ] . "'>\n" ) ;
2016-10-05 14:30:55 +01:00
}
2019-05-02 14:46:57 +01:00
}
if ( $ title ) {
push ( @ output , " </td>\n" ) ;
}
$ e + + ;
if ( ! ( $ e % 2 ) ) {
push ( @ output , " </tr>\n" ) ;
push ( @ output , " <tr>\n" ) ;
2016-10-05 14:30:55 +01:00
}
}
if ( $ title ) {
2017-07-26 10:26:12 +01:00
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2016-10-05 14:30:55 +01:00
}
2017-07-26 10:26:12 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2016-10-05 14:30:55 +01:00
}
1 ;