added support to include username and password in the 'url_prefix' option in the 'emailreports' module

This commit is contained in:
Jordi Sanfeliu 2014-05-21 16:38:38 +02:00
parent cfd44576ce
commit 204f470aca
2 changed files with 13 additions and 3 deletions

View File

@ -3,6 +3,8 @@
- Added a complete statistical Libvirt (libvirt) graph.
- Added Upstart job. [#46]
- Added more verbosity during the startup.
- Added support to include username and password in the 'url_prefix' option of
the 'emailreports' module.
- Fixed regexp that prevented collecting LOADPCT and ITEMP values in 'apcupsd'
module.
(thanks to Patrick Fallberg, patrick AT fallberg.net)

View File

@ -40,7 +40,13 @@ sub emailreports_send {
logger("$myself: sending $report reports.");
my $uri = URI->new($emailreports->{url_prefix});
my $hostname = $uri->host;
my $scheme = $uri->scheme || "";
my $userinfo = $uri->userinfo || "";
$userinfo .= "@" unless !$userinfo;
my $hostname = $uri->host || "";
my $port = $uri->port || "";
my $prefix = "$scheme://$userinfo$hostname:$port";
my $html = <<"EOF";
<html>
@ -87,7 +93,7 @@ EOF
if lc($config->{accept_selfsigned_certs}) eq "y";
# generate the graphs and get the html source
my $url = $emailreports->{url_prefix} . $base_cgi . "/monitorix.cgi?mode=localhost&graph=_$g&when=$when&color=white";
my $url = $prefix . $base_cgi . "/monitorix.cgi?mode=localhost&graph=_$g&when=$when&color=white";
my $ua = LWP::UserAgent->new(timeout => 30, $ssl);
my $response = $ua->request(HTTP::Request->new('GET', $url));
@ -124,7 +130,9 @@ EOF
$images->{"image_$g$n"} = "";
($url) = $_ =~ m/<img src='(.*?)' /;
$response = $ua->request(HTTP::Request->new('GET', $url));
my $uri = URI->new($url);
my $path = $uri->path || "";
$response = $ua->request(HTTP::Request->new('GET', "$prefix$path"));
$images->{"image_$g$e$n"} = $response->content;
$n++;
} else {