mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-08-10 07:54:39 +00:00
discovering the version of rtorrent, and depending on that, using the correct functions in the xmlrpc call
This commit is contained in:
parent
3cb7002287
commit
54ad1ad4d5
8 changed files with 272 additions and 68 deletions
|
@ -25,7 +25,6 @@
|
|||
# src "socket" when using scgi_socket, or anything else when using scgi_port
|
||||
# socket rTorrent's rpc socket (scgi_local) - using scgi_local - needed, when "src" is 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
|
||||
#
|
||||
|
@ -34,13 +33,11 @@
|
|||
# env.src socket
|
||||
# env.socket /home/user/torrent/.socket/rpc.socket,/home/user/torrent/.socket/rpc.socket
|
||||
# env.category Category
|
||||
# env.api current
|
||||
#
|
||||
# [rtom_allsessions_*]
|
||||
# user username
|
||||
# env.port 5000,5001,5002,5003
|
||||
# env.category Category
|
||||
# env.api pre09
|
||||
#
|
||||
#%# family=auto
|
||||
|
||||
|
@ -79,18 +76,48 @@ my $src = $ENV{"src"} || "";
|
|||
my @sockets = split /,/, $ENV{"socket"} || "";
|
||||
my $ip = $ENV{"ip"} || "127.0.0.1";
|
||||
my @ports = split /,/, $ENV{"port"} || "";
|
||||
my $api = $ENV{"api"} || "current";
|
||||
|
||||
# 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><string>([A-Z0-9]+)<\/string><\/value>/;
|
||||
|
||||
my $function_multicall;
|
||||
my $function_hash;
|
||||
|
||||
foreach ( @views ) {
|
||||
my $num = 0;
|
||||
my $line = "";
|
||||
if ($api =~ /pre09/) {
|
||||
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.multicall</methodName><params><param><value><string>${_}</string></value></param><param><value><string>d.get_hash=</string></value></param></params></methodCall>";
|
||||
} else {
|
||||
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>d.multicall2</methodName><params><param><value><string></string></value></param><param><value><string>${_}</string></value></param><param><value><string>d.hash=</string></value></param></params></methodCall>";
|
||||
}
|
||||
$function_multicall = rtorrent_version_lower_than('0.9.0')? 'd.multicall' : 'd.multicall2';
|
||||
$function_hash = rtorrent_version_lower_than('0.9.0')? 'd.get_hash=' : 'd.hash=';
|
||||
$line = "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>$function_multicall</methodName><params><param><value><string>${_}</string></value></param><param><value><string>$function_hash</string></value></param></params></methodCall>";
|
||||
my $llen = length $line;
|
||||
my $header = "CONTENT_LENGTH\000${llen}\000SCGI\001\000";
|
||||
my $hlen = length $header;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue