Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / other / boinc_processes @ cf19700c

Historique | Voir | Annoter | Télécharger (4,2 ko)

1
#!/usr/bin/perl -w
2
#
3
# Plugin for monitoring boinc processes
4
#
5
# Parameters:
6
#
7
#	password	-- The password for RPC authentication
8
#			   (default: boinc_cmd will look for a file 
9
#			   'gui_rpc_auth.cfg' and use the password in it)
10
#       host 		-- the host to connect to (default: localhost)
11
#	port 		-- optional (default: 31416)
12
#
13
# This plugin can monitor boinc processes running on local/remote machines. 
14
# You can see the progress on various projects.
15
#
16
# Author: Petr Ruzicka <petr.ruzicka@gmail.com>
17
# GPL v3
18
#
19
#%# family=auto
20
#%# capabilities=autoconf
21

    
22
use IO::Socket;
23
use Digest::MD5 qw(md5_hex);
24

    
25

    
26
if ($ENV{'password_path'}) {
27
  $password = $ENV{'password_path'};
28
} else {
29
    $password = $ENV{'password'} || `cat /var/lib/boinc/gui_rpc_auth.cfg 2>/dev/null`;
30
  }
31

    
32
my $host = $ENV{'host'} || '127.0.0.1';
33
my $port = $ENV{'port'} || '31416';
34

    
35

    
36
sub autoconf {
37
  my $client = new IO::Socket::INET (
38
  PeerAddr => $host,
39
  PeerPort => $port,
40
  Proto => 'tcp' );
41

    
42
  if ($client) {
43
    print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
44

    
45
    {
46
      local $/ = "\003";
47
      $reply = <$client>;
48
    }
49

    
50
    $reply =~ /<nonce>(.*)<\/nonce>/;
51
    $hash = md5_hex($1, $password);
52
	
53
    print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
54
	
55
    {
56
      local $/ = "\003";
57
      $reply = <$client>;
58
    }
59
	
60
    if ($reply =~ /<authorized\/>/) {
61
      print "yes\n";
62
      exit 0;
63
    }
64
  }
65
  print "no\n";
66
  exit 1;
67
}
68

    
69
sub config {
70
  my $client = IO::Socket::INET->new ( PeerAddr => $host,
71
    				       PeerPort => $port,
72
				       Proto => 'tcp' )
73
  or die "Can't bind : $@\n"; 
74

    
75
  print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
76

    
77
  {	
78
    local $/ = "\003";
79
    $reply = <$client>;
80
  }
81

    
82
  $reply =~ /<nonce>(.*)<\/nonce>/;
83
  my $hash = md5_hex($1, $password);
84
	
85
  print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
86
	
87
  {
88
    local $/ = "\003";
89
    $reply = <$client>;
90
  }
91
	
92
  if ($reply !~ /<authorized\/>/) {
93
    die "Wrong password: $_";
94
  }
95
    
96
  print $client "<boinc_gui_rpc_request><get_state></boinc_gui_rpc_request>";
97

    
98
  while (chomp($reply = <$client>) && ($reply ne "</boinc_gui_rpc_reply>")) {
99
    if ($reply =~ /<domain_name>(.*)<\/domain_name>/) {
100
      print "graph_title BOINC task progress [$1]\n";
101
      print "graph_args -l 0\n";
102
      print "graph_vlabel %\n";
103
    }  
104
    if ($reply =~ /<project_name>(.*)<\/project_name>/) {
105
      my $boinc_munin_name=$1;
106
      $boinc_munin_name =~ /(\w+).*/;
107
      print "$1.label $boinc_munin_name\n";
108
    }
109
  }
110
  close ($client);
111
}
112

    
113
sub report {
114
  my $client = IO::Socket::INET->new ( PeerAddr => $host,
115
    				       PeerPort => $port,
116
				       Proto => 'tcp' )
117
  or die "Can't bind : $@\n"; 
118

    
119
  print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
120

    
121
  {	
122
    local $/ = "\003";
123
    $reply = <$client>;
124
  }
125

    
126
  $reply =~ /<nonce>(.*)<\/nonce>/;
127
  my $hash = md5_hex($1, $password);
128
	
129
  print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
130
	
131
  {
132
    local $/ = "\003";
133
    $reply = <$client>;
134
  }
135
	
136
  if ($reply !~ /<authorized\/>/) {
137
    die "Wrong password: $_";
138
  }
139
    
140
  print $client "<boinc_gui_rpc_request><get_state></boinc_gui_rpc_request>";
141
    
142
  while (chomp($reply = <$client>) && ($reply ne "</boinc_gui_rpc_reply>")) {
143
    if ($reply =~ /<project_name>(\w+).*<\/project_name>/) {
144
      $project = $1;
145
      $fraction_done=0;
146
      while (chomp($reply = <$client>) && ($reply ne "<project>") && ($reply ne "</client_state>")) {
147
        if ($reply =~ /\s*<active_task_state>1<\/active_task_state>/) {
148
	  while (chomp($reply = <$client>) && ($reply ne "</active_task>")) {
149
            if ($reply =~ /<fraction_done>(.*)<\/fraction_done>/) {
150
	      $fraction_done+=int($1*100 + .5 * ($1*100 <=> 0));
151
	    }
152
	  }
153
	}
154
      }
155
      print "$project.value $fraction_done\n";
156
    }
157
  }
158
  close ($client);
159
}
160

    
161
if (defined $ARGV[0]) {
162
  my $arg = $ARGV[0];
163
  my %funcs = ( config => \&config,
164
		autoconf => \&autoconf,
165
		report => \&report
166
	      );
167

    
168
  if (exists $funcs{$arg}) {
169
    $funcs{$arg}->();
170
  }
171
  else {
172
    $funcs{"report"}->();
173
  }
174
} else {
175
    report();
176
  }