From patchwork Thu Apr 1 13:35:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leo-Andres Hofmann X-Patchwork-Id: 4013 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4FB41x1bH3z40R0 for ; Thu, 1 Apr 2021 13:35:33 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4FB41t47GNz20M; Thu, 1 Apr 2021 13:35:30 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4FB41t2hCgz2ydr; Thu, 1 Apr 2021 13:35:30 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4FB41s6SlZz2xcy for ; Thu, 1 Apr 2021 13:35:29 +0000 (UTC) Received: from arche.uberspace.de (arche.uberspace.de [185.26.156.147]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4FB41s2qNQz1T5 for ; Thu, 1 Apr 2021 13:35:29 +0000 (UTC) Received: (qmail 10550 invoked from network); 1 Apr 2021 13:35:28 -0000 Received: from localhost (HELO localhost) (127.0.0.1) by arche.uberspace.de with SMTP; 1 Apr 2021 13:35:28 -0000 From: Leo-Andres Hofmann To: development@lists.ipfire.org Subject: [PATCH 3/3] rrdimage: Switch graphs.pl to the new graph scripts Date: Thu, 1 Apr 2021 15:35:16 +0200 Message-Id: <20210401133516.1058-3-hofmann@leo-andres.de> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20210401133516.1058-1-hofmann@leo-andres.de> References: <20210401133516.1058-1-hofmann@leo-andres.de> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1617284129; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p41NECZxMlrd8RmKENaE8sM7ckY6Hy3uaQibFSnCWOg=; b=aS8L1yXHep0ZbCa2Pm6sByZC0RrUzpiEQPtiJFbolqeSVlt1kozjJkUeGlTPe0I6QzlkyE vRWCHvmk4hEVrFz+FWqxizsmuS4oxEiwWZHoDSkOMB7C0kxf729H4XQPgf6gwn6kCOioZO QB65ppV3hN5vtNKf1JB7LWXcAf5xFL/zWC7lv8YH2Y9e84nN+SDZvaFUD9JpFVPS8XxQ2z A6BNGkddBKGkRoEb58SePEKYsvM4eFfdvXhj/TKCvuKa2r3n1ogg7ewyXgLuzuJs7ETHyS fY49FMVSZouZAeg4yIftr+k77YrmYvBME53QJFbqKoRHFJwifEMdecSmkoTXLQ== ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1617284129; a=rsa-sha256; cv=none; b=FJ0KsjDWnlBrsno9XcpCKibSIRWysBOnder1f/Jl1qeWAXFAZzPi15prrDlc3WPgSBCAPO Kxzy7NRQm1EpmZiPPwVjr0bagSZ6AHEV0BHTNBZI3cTNuzCi1MB2xh16kbAfMDH6sggkXz zbqJ7mkbikXjewa7dNBZViIaaT7QbRlgApxtJ9g9nwXFRueqGU5/VtFqvpCRlE8Z0Inn1l Eh3SxbIc9ORHMLUIYLQOafzbX6V/uukUk66kv5gpIf1iWHKwjQOcJNhF9QS0wioNDvmIVt 7cr9SCFGuA8Xpm47SDba1P2tE/uWeoYFSlb6LcMIEXaRXvH9ynCsiY3CQ3EVRQ== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=none; spf=pass (mail01.ipfire.org: domain of hofmann@leo-andres.de designates 185.26.156.147 as permitted sender) smtp.mailfrom=hofmann@leo-andres.de X-Rspamd-Queue-Id: 4FB41s2qNQz1T5 Authentication-Results: mail01.ipfire.org; dkim=none; dmarc=none; spf=pass (mail01.ipfire.org: domain of hofmann@leo-andres.de designates 185.26.156.147 as permitted sender) smtp.mailfrom=hofmann@leo-andres.de X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-4.04 / 11.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; IP_REPUTATION_HAM(-2.04)[asn: 205766(-0.29), country: DE(-0.01), ip: 185.26.156.147(-0.73)]; TO_DN_NONE(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; RCPT_COUNT_ONE(0.00)[1]; DMARC_NA(0.00)[leo-andres.de]; R_SPF_ALLOW(-0.20)[+mx]; MID_CONTAINS_FROM(1.00)[]; MIME_HTML_ONLY(0.20)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:~]; ASN(0.00)[asn:205766, ipnet:185.26.156.0/24, country:DE]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[99.98%] X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" "makegraphbox" is modified to remove the old iframe method and output a modern div container instead. Graph errors are now returned, to be displayed by getrrdimage.cgi. entropy.cgi and netovpnsrv.cgi are modified to ensure compatibility. Add cache control HTTP header to image output. Signed-off-by: Leo-Andres Hofmann --- config/cfgroot/graphs.pl | 86 +++++++++++++++++++++---------------- html/cgi-bin/entropy.cgi | 2 +- html/cgi-bin/netovpnsrv.cgi | 2 +- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/config/cfgroot/graphs.pl b/config/cfgroot/graphs.pl index beddff032..cf4a30de3 100644 --- a/config/cfgroot/graphs.pl +++ b/config/cfgroot/graphs.pl @@ -24,6 +24,7 @@ package Graphs; use strict; use RRDs; +use experimental 'smartmatch'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; @@ -99,26 +100,35 @@ foreach (@sensorsdir){ &General::readhash("${General::swroot}/sensors/settings", \%sensorsettings); # Generate a nice box for selection of time range in graphs -# this will generate a nice iframe for the cgi every klick for -# the graph will be handled inside the iframe +# this will generate a nice div box for the cgi every klick for +# the graph will be handled by javascript # 0 is the cgi refering to # 1 is the graph name -# 2 is the time range for the graph -# 3 if given is the height of the iframe default if nothing is given +# 2 is the time range for the graph (optional) sub makegraphbox { - print "
"; - print "".$Lang::tr{'hour'}.""; - print " - "; - print "".$Lang::tr{'day'}.""; - print " - "; - print "".$Lang::tr{'week'}.""; - print " - "; - print "".$Lang::tr{'month'}.""; - print " - "; - print "".$Lang::tr{'year'}.""; - print "
"; - print ""; + my ($origin, $name, $default_range) = @_; + + # Optional time range: Default to "day" unless otherwise specified + $default_range = "day" unless ($default_range ~~ @time_ranges); + + print < +
    +END + + # Print range select buttons + foreach my $range (@time_ranges) { + print < +END + } + + print < + $Lang::tr{'graph'} ($name) + +END } # Generate the CPU Graph for the current period of time for values given by @@ -248,7 +258,7 @@ sub updatecpugraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR; } # Generate the Load Graph for the current period of time for values given by collecd @@ -280,7 +290,7 @@ sub updateloadgraph { "LINE1:load1".$color{"color18"}, ); $ERROR = RRDs::error; - print "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for load: ".$ERROR."\n" if $ERROR; } # Generate the Memory Graph for the current period of time for values given by collecd @@ -336,7 +346,7 @@ sub updatememorygraph { "GPRINT:freepct:LAST:%3.2lf%%\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR; } # Generate the Swap Graph for the current period of time for values given by collecd @@ -385,7 +395,7 @@ sub updateswapgraph { "GPRINT:freepct:LAST:%3.2lf%%\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR; } # Generate the Process Cpu Graph for the current period of time for values given by collecd @@ -432,7 +442,7 @@ sub updateprocessescpugraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for processes: ".$ERROR."\n" if $ERROR; } # Generate the Process Memory Graph for the current period of time for values given by collecd @@ -478,7 +488,7 @@ sub updateprocessesmemorygraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for processesmemory: ".$ERROR."\n" if $ERROR; } # Generate the Disk Graph for the current period of time for values given by collecd @@ -522,7 +532,7 @@ sub updatediskgraph { "GPRINT:write:LAST:%8.1lf %sBps\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for ".$disk.": ".$ERROR."\n" if $ERROR; } # Generate the Interface Graph for the current period of time for values given by collecd @@ -561,7 +571,7 @@ sub updateifgraph { "GPRINT:outgoing:LAST:%8.1lf %sBps\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; } sub updatevpngraph { @@ -598,7 +608,7 @@ sub updatevpngraph { "GPRINT:outgoing:LAST:%8.1lf %sBps\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; } sub updatevpnn2ngraph { @@ -661,7 +671,7 @@ sub updatevpnn2ngraph { "GPRINT:compression_out:LAST:%8.1lf %sBps\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for ".$interface.": ".$ERROR."\n" if $ERROR; } # Generate the Firewall Graph for the current period of time for values given by collecd @@ -716,7 +726,7 @@ sub updatefwhitsgraph { "GPRINT:portscan:LAST:%8.1lf %sBps\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for firewallhits: ".$ERROR."\n" if $ERROR; } # Generate the Line Quality Graph for the current period of time for values given by collecd @@ -758,7 +768,7 @@ sub updatepinggraph { "GPRINT:roundtrip:LAST:%3.2lf ms\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for link quality: ".$ERROR."\n" if $ERROR; } sub updatewirelessgraph { @@ -793,7 +803,7 @@ sub updatewirelessgraph { "GPRINT:power:LAST:%5.1lf %sdBm\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for wireless: ".$ERROR."\n" if $ERROR; } # Generate the HDD Temp Graph for the current period of time for values given by collecd and lm_sensors @@ -827,7 +837,7 @@ sub updatehddgraph { "GPRINT:temperature:LAST:%3.0lf °C\\j", ); $ERROR = RRDs::error; - print "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for hdd-".$disk.": ".$ERROR."\n" if $ERROR; } # Generate the Temp Graph for the current period of time for values given by collecd and lm_sensors @@ -875,7 +885,7 @@ sub updatehwtempgraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for HDD Temp: ".$ERROR."\n" if $ERROR; } # Generate the Fan Graph for the current period of time for values given by collecd and lm_sensors @@ -922,7 +932,7 @@ sub updatehwfangraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for Fan Speed: ".$ERROR."\n" if $ERROR; } # Generate the Voltage Graph for the current period of time for values given by collecd and lm_sensors @@ -969,7 +979,7 @@ sub updatehwvoltgraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for Voltage: ".$ERROR."\n" if $ERROR; } @@ -1051,7 +1061,7 @@ sub updateqosgraph { } RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for qos device ".$qossettings{'DEV'}.": ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for qos device ".$qossettings{'DEV'}.": ".$ERROR."\n" if $ERROR; } # Generate the CPU Frequency Graph for the current period of time for values given by collectd an lm_sensors @@ -1090,7 +1100,7 @@ sub updatecpufreqgraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR; } # Generate the Thermal Zone Temp CPU Graph @@ -1129,7 +1139,7 @@ sub updatethermaltempgraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for thermal temp: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for thermal temp: ".$ERROR."\n" if $ERROR; } @@ -1174,7 +1184,7 @@ sub updateentropygraph { RRDs::graph (@command); $ERROR = RRDs::error; - print "Error in RRD::graph for entropy: ".$ERROR."\n" if $ERROR; + return "Error in RRD::graph for entropy: ".$ERROR."\n" if $ERROR; } sub updateconntrackgraph { @@ -1202,5 +1212,5 @@ sub updateconntrackgraph { RRDs::graph(@command); $ERROR = RRDs::error; - print STDERR "Error in RRD::Graph for conntrack: " . $ERROR . "\n" if $ERROR; + return "Error in RRD::Graph for conntrack: " . $ERROR . "\n" if $ERROR; } diff --git a/html/cgi-bin/entropy.cgi b/html/cgi-bin/entropy.cgi index d7a9ca5d8..f8045db5a 100644 --- a/html/cgi-bin/entropy.cgi +++ b/html/cgi-bin/entropy.cgi @@ -45,7 +45,7 @@ if ( $querry[0] ne~ "") { &Header::openbigbox('100%', 'left'); &Header::openbox('100%', 'center', $Lang::tr{'entropy'}); - &Graphs::makegraphbox("entropy.cgi", "day"); + &Graphs::makegraphbox("entropy.cgi", "entropy", "day"); &Header::closebox(); # Check for hardware support. diff --git a/html/cgi-bin/netovpnsrv.cgi b/html/cgi-bin/netovpnsrv.cgi index 77c69cddb..ab3548713 100755 --- a/html/cgi-bin/netovpnsrv.cgi +++ b/html/cgi-bin/netovpnsrv.cgi @@ -75,7 +75,7 @@ if ( $querry[0] ne ""){ if (@vpns || %ipsecgraphs) { foreach my $name (sort keys %ipsecgraphs) { &Header::openbox('100%', 'center', "$Lang::tr{'ipsec connection'}: $name"); - &Graphs::makegraphbox("netovpnsrv.cgi", $ipsecgraphs{$name}, "day"); + &Graphs::makegraphbox("netovpnsrv.cgi", "ipsec-$ipsecgraphs{$name}", "day"); &Header::closebox(); }