From 54c9563274aac0dfbf38d5bf8347ee56563004f0 Mon Sep 17 00:00:00 2001 From: Rowan Wookey Date: Fri, 3 Jul 2020 18:00:59 +0100 Subject: [PATCH] Modified http_request_time to allow specifying a user agent Similar to other settings for this plugin, there is a new env.urlN_agent setting which allows specifying a user agent --- plugins/http/http_request_time | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/http/http_request_time b/plugins/http/http_request_time index 8c666f12..cb8bebfc 100755 --- a/plugins/http/http_request_time +++ b/plugins/http/http_request_time @@ -16,6 +16,7 @@ env.url3_name some_munin_internal_name env.url3_label Some random page on our website env.url3_proxy http://firewall:3128 + env.url3_agent Mozilla/5.0 env.timeout 3 Timeout is the timeout of any HTTP request. Tune to avoid a complete @@ -70,11 +71,13 @@ for (my $i = 1; $ENV{"url$i"}; $i++) my $proxy = $ENV{"url${i}_proxy"}; my $name = $ENV{"url${i}_name"} || clean($url); my $label = $ENV{"url${i}_label"} || $url; + my $agent = $ENV{"url${i}_agent"}; $URLS{$name}={ url=>$url, proxy=>$proxy, label=>$label, + agent=>$agent, time=>'U' }; } @@ -141,9 +144,15 @@ if ( defined $ARGV[0] and $ARGV[0] eq "config" ) } my $ua = LWP::UserAgent->new(timeout => $timeout); +my $defaultAgent = $ua->agent; foreach my $name (keys %URLS) { my $url = $URLS{$name}; + if ($url->{agent}) { + $ua->agent($url->{agent}); + } else { + $ua->agent($defaultAgent); + } if ($url->{proxy}) { $ua->proxy(['http', 'ftp'], $url->{proxy}); }