1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-08-07 06:33:15 +00:00

discovering the version of rtorrent, and depending on that, using the correct functions in the xmlrpc call

This commit is contained in:
Younes Ichiche 2020-03-31 21:24:50 +02:00 committed by Lars Kruse
parent 3cb7002287
commit 54ad1ad4d5
8 changed files with 272 additions and 68 deletions

View file

@ -27,7 +27,6 @@
# ip rTorrent's ip address - using scgi_port - needed, when "src" is NOT set to "socket"
# port rTorrent's scgi port (scgi_port) - using scgi_port - needed, when "src" is NOT set to "socket"
# category Change graph category
# api use "pre09" (pre 0.9.0) or "current" (0.9.0+, the default) API calls
#
# Configuration example
#
@ -64,16 +63,40 @@ my $src = $ENV{"src"} || "";
my $ip = $ENV{"ip"} || "127.0.0.1";
my $port = $ENV{"port"} || "5000";
my $socket = $ENV{"socket"} || "";
my $api = $ENV{"api"} || "current";
my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
my $line = "";
if ($api =~ /pre09/) {
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_memory_usage</methodName></methodCall>";
} else {
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>pieces.memory.current</methodName></methodCall>";
# detect rtorrent version
use version;
my $rtorrent_version;
sub rtorrent_version_lower_than {
if (not length $rtorrent_version){
if ( ( defined $src ) && ( $src eq "socket" ) ) {
socket( SOCK, PF_UNIX, SOCK_STREAM, 0 ) or die;
connect( SOCK, sockaddr_un( $socket ) ) or die $!;
} else {
socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname( "tcp" ) );
connect( SOCK, sockaddr_in( $port, inet_aton( $ip ) ) );
}
my $line_version= "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>system.client_version</methodName></methodCall>";
my $llen = length $line_version;
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
my $hlen = length $header;
$line_version= "${hlen}:${header},${line_version}";
print SOCK $line_version;
flush SOCK;
my $pattern = qr/<value><string>([0-9.]+)<\/string><\/value>/;
while ( $line = <SOCK> ) {
if ( $line =~ /$pattern/ ) {
$rtorrent_version = $1;
}
}
close (SOCK);
}
return version->parse($rtorrent_version) < version->parse($_[0]);
}
my $pattern = qr/<value><(int|i4|i8|ex\.i8)>(\d+)<\/(int|i4|i8|ex\.i8)><\/value>/;
my $function = rtorrent_version_lower_than('0.9.0') ? 'get_memory_usage' : 'pieces.memory.current';
my $line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>$function</methodName></methodCall>";
my $llen = length $line;
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
my $hlen = length $header;