This file is indexed.

/usr/share/perl5/OAR/PingChecker.pm is in oar-server 2.5.4-2+deb8u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# $Id$
package OAR::PingChecker;
require Exporter;

use strict;
use Data::Dumper;
use OAR::Modules::Judas qw(oar_debug oar_warn oar_error send_log_by_email set_current_log_category);
use OAR::Conf qw(init_conf dump_conf get_conf is_conf);
use IPC::Open3;
use OAR::Tools;

require Exporter;
our (@ISA,@EXPORT,@EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(ping_hosts sentinelle_hosts test_hosts);

# Log category
set_current_log_category('main');

my $Timeout_ping = 5;
my $Timeout_fping = 15;
my $Timeout_nmap = 30;
my $Timeout_sentinelle = 300;
my $Timeout_script_sentinelle = 300;
my $Default_timeout = 300;

#resolve host name and give its IP or return 0
sub get_host_ip($){
    my ($host_name) = shift;
    my (@addrlist,$name,$altnames,$addrtype,$len);
    my ($ip);
 
    if (!(($name, $altnames, $addrtype, $len, @addrlist) = gethostbyname($host_name))) {
        return (0);
    }else{
        $ip=join('.',(unpack("C4",$addrlist[0])));
        return ($ip);
    }
}

#Launch the right sub
sub test_hosts(@){
    init_conf($ENV{OARCONFFILE});
    if (is_conf("OAR_SSH_CONNECTION_TIMEOUT")){
        OAR::Tools::set_ssh_timeout(get_conf("OAR_SSH_CONNECTION_TIMEOUT"));
    }
    if (is_conf("PINGCHECKER_TAKTUK_ARG_COMMAND") and is_conf("TAKTUK_CMD")){
        return(taktuk_hosts(@_));
    }elsif (is_conf("PINGCHECKER_SENTINELLE_SCRIPT_COMMAND")){
        return(sentinelle_script_hosts(@_));
    }elsif (is_conf("PINGCHECKER_FPING_COMMAND")){
        return(fping_hosts(@_));
    }elsif (is_conf("PINGCHECKER_NMAP_COMMAND")){
        return(nmap_hosts(@_));
    }elsif (is_conf("PINGCHECKER_GENERIC_COMMAND")){
        return(generic_hosts(@_));
    }else{
        return(ping_hosts(@_));
    }
}

#Ping hosts and return each one dead
# arg1 --> array of hosts to test
sub ping_hosts(@){
    my @hosts = @_;

    my @bad_hosts;
    my $exit_value;
    foreach my $i (@hosts){
        oar_debug("[PingChecker] PING $i\n");
        $ENV{IFS}="";
        $ENV{ENV}="";
        eval {
            $SIG{ALRM} = sub { die "alarm\n" };
            alarm($Timeout_ping);
            #$exit_value = system("ping -c 1 $i > /dev/null");
            $exit_value = system("oardodo ping -c 10 -l 9 $i > /dev/null");
            alarm(0);
        };
        oar_debug("[PingChecker] PONG with exit_value=$exit_value and alarm=$@\n");
        if (($exit_value != 0) || ($@)){
            push(@bad_hosts, $i);
        }
    }

    return(@bad_hosts);
}

#Test hosts with taktuk and return each one dead
# arg1 --> array of hosts to test
sub taktuk_hosts(@){
    my @hosts = @_;

    init_conf($ENV{OARCONFFILE});
    my $taktuk_cmd = get_conf("TAKTUK_CMD");
    oar_debug("[PingChecker] command to run : $taktuk_cmd\n");
    my ($cmd, @null) = split(" ",$taktuk_cmd);
    oar_debug("[PingChecker] command to run with arguments : $cmd\n");
    if (!defined($taktuk_cmd) || (! -x $cmd)){
        oar_error("[PingChecker] You call taktuk_hosts but TAKTUK_CMD in oar.conf is not valid.\n");
        return(@hosts);
    }

    my $openssh_cmd = get_conf("OPENSSH_CMD");
    $openssh_cmd = OAR::Tools::get_default_openssh_cmd() if (!defined($openssh_cmd));

    my %check_test_nodes;

    $taktuk_cmd .= " -c '$openssh_cmd'".' -o status=\'"STATUS $host $line\n"\' -f - '.get_conf("PINGCHECKER_TAKTUK_ARG_COMMAND");

    my @bad_hosts;
    oar_debug("[PingChecker] $taktuk_cmd\n");
    $ENV{IFS}="";
    $ENV{ENV}="";
    my $pid;
    eval {
        $SIG{ALRM} = sub { kill(19,$pid); die("alarm\n") };
        alarm(OAR::Tools::get_taktuk_timeout());
        $pid = open3(\*WRITER, \*READER, \*ERROR, $taktuk_cmd);
        foreach my $i (@hosts){
            print(WRITER "$i\n");
            $check_test_nodes{$i} = 1;
        }
        close(WRITER);
        while(<READER>){
            if ($_ =~ /^STATUS ([\w\.\-\d]+) (\d+)$/){
                if ($2 == 0){
                    delete($check_test_nodes{$1}) if (defined($check_test_nodes{$1}));
                }
            }else{
                oar_debug("[PingChecker][TAKTUK OUTPUT] $_");
            }
        }
        close(ERROR);
        close(READER);
        waitpid($pid, 0);
        alarm(0);
    };
    oar_debug("[PingChecker] End of command; alarm=$@\n");
    if ($@){
        oar_error("[PingChecker] taktuk command times out : it is bad\n");
        if (defined($pid)){
            # Kill all taktuk children
            my ($children,$cmd_name) = OAR::Tools::get_one_process_children($pid);
            kill(9,@{$children});
        }
#        return(@hosts);
    }#else{
    @bad_hosts = keys(%check_test_nodes);
    return(@bad_hosts);
#    }
}


#Test hosts with sentinelle script and return each one dead
# arg1 --> array of hosts to test
sub sentinelle_script_hosts(@){
    my @hosts = @_;

    # Set the parameter of the -c option of sentinelle
    init_conf($ENV{OARCONFFILE});
    my $sentinelle_cmd = get_conf("PINGCHECKER_SENTINELLE_SCRIPT_COMMAND");
    oar_debug("[PingChecker] command to run : $sentinelle_cmd\n");
    my ($cmd, @null) = split(" ",$sentinelle_cmd);
    oar_debug("[PingChecker] command to run with arguments : $cmd\n");
    if (!defined($sentinelle_cmd) || (! -x $cmd)){
        oar_error("[PingChecker] You call sentinelle_script_hosts but PINGCHECKER_SENTINELLE_SCRIPT_COMMAND in oar.conf is not valid\n");
        return(@hosts);
    }
    
    my $openssh_cmd = get_conf("OPENSSH_CMD");
    $openssh_cmd = OAR::Tools::get_default_openssh_cmd() if (!defined($openssh_cmd));

    my %check_test_nodes;
    $sentinelle_cmd .= " -c '$openssh_cmd' -f - ";

    my @bad_hosts;
    oar_debug("[PingChecker] $sentinelle_cmd \n");
    $ENV{IFS}="";
    $ENV{ENV}="";
    eval {
        my $pid;
        $SIG{ALRM} = sub { kill(9,$pid); die("alarm\n") };
        alarm($Timeout_script_sentinelle);
        $pid = open3(\*WRITER, \*READER, \*ERROR, $sentinelle_cmd);
        foreach my $i (@hosts){
            print(WRITER "$i\n");
            $check_test_nodes{$i} = 1;
        }
        close(WRITER);
        while(<ERROR>){
            chomp($_);
            #if ($_ =~ m/^([\w\.]+)\s:\sBAD\s.*$/m){
            if ($_ =~ m/^([\w\.\-]+)\s:\sBAD\s.*$/m){
                if ($check_test_nodes{$1} == 1){
                    oar_debug("[PingChecker] Bad host = $1 \n");
                    push(@bad_hosts, $1);
                }
            }
        }
        close(READER);
        close(ERROR);
        waitpid($pid, 0);
        alarm(0);
    };
    oar_debug("[PingChecker] End of command; alarm=$@\n");
    if ($@){
        oar_error("[PingChecker] sentinelle script command times out : it is bad\n");
        return(@hosts);
    }else{
        return(@bad_hosts);
    }
}

#Ping hosts with fping program return each one dead
# arg1 --> array of hosts to test
sub fping_hosts(@){
    my @hosts = @_;

    # Get fping command from oar.conf
    init_conf($ENV{OARCONFFILE});
    my $fping_cmd = get_conf("PINGCHECKER_FPING_COMMAND");
    oar_debug("[PingChecker] command to run : $fping_cmd\n");
    my ($cmd, @null) = split(" ",$fping_cmd);
    oar_debug("[PingChecker] command to run with arguments : $cmd\n");
    if (!defined($fping_cmd) || (! -x $cmd)){
        oar_error("[PingChecker] You want to call fping test method but PINGCHECKER_FPING_COMMAND in oar.conf is not valid\n");
        return(@hosts);
    }

    $fping_cmd .= " -u";
    my %check_test_nodes;
    foreach my $i (@hosts){
        $fping_cmd .= " $i";
        $check_test_nodes{$i} = 1;
    }

    my @bad_hosts;
    oar_debug("[PingChecker] $fping_cmd\n");
    $ENV{IFS}="";
    $ENV{ENV}="";
    eval {
        my $pid;
        $SIG{ALRM} = sub { kill(9,$pid); die("alarm\n") };
        alarm($Timeout_fping);
        $pid = open3(\*WRITER, \*READER, \*ERROR, $fping_cmd);
        close(WRITER);
        foreach my $i (\*READER, \*ERROR){
            while(<$i>){
                chomp($_);
                #$_ =~ m/^\s*([\w\.]+)\s*$/m;
                $_ =~ m/^\s*([\w\.-\d]+)\s*(.*)$/m;
                if ($check_test_nodes{$1} == 1){
                    if (!defined($2) || !($2 =~ m/alive/m)){
                        oar_debug("[PingChecker] Bad host = $1 \n");
                        push(@bad_hosts, $1);
                    }
                }
            }
        }
        close(ERROR);
        close(READER);
        waitpid($pid, 0);
        alarm(0);
    };
    oar_debug("[PingChecker] End of command; alarm=$@\n");
    if ($@){
        oar_error("[PingChecker] fping command times out : it is bad\n");
        return(@hosts);
    }else{
        return(@bad_hosts);
    }
}
 

# use nmap to determine if hosts are alive or not
# arg1 --> array of hosts to test
sub nmap_hosts(@){
    my @hosts = @_;

    # Get nmap command from oar.conf
    init_conf($ENV{OARCONFFILE});
    my $nmap_cmd = get_conf("PINGCHECKER_NMAP_COMMAND");
    oar_debug("[PingChecker] command to run : $nmap_cmd\n");
    my ($cmd, @null) = split(" ",$nmap_cmd);
    oar_debug("[PingChecker] command to run with arguments : $cmd\n");
    if (!defined($nmap_cmd) || (! -x $cmd)){
        oar_error("[PingChecker] You want to call nmap test method but PINGCHECKER_NMAP_COMMAND in oar.conf is not valid\n");
        return(@hosts);
    }

    $nmap_cmd .= " -oG -";
    my %ip2name;
    my @bad_hosts;
    foreach my $i (@hosts){
        my $ip = get_host_ip($i);
        if ($ip != 0){
            if (!defined($ip2name{$ip})){
                $nmap_cmd .= " $ip";
            }
            push(@{$ip2name{$ip}}, $i);
        }
    }

    my %good_hosts;
    oar_debug("[PingChecker] $nmap_cmd\n");
    $ENV{IFS}="";
    $ENV{ENV}="";
    eval {
        my $pid;
        $SIG{ALRM} = sub { kill(9,$pid); die("alarm\n") };
        alarm($Timeout_nmap);
        $pid = open3(\*WRITER, \*READER, \*ERROR, $nmap_cmd);
        close(WRITER);
        while(<READER>){
            chomp($_);
            if ($_ =~ m/^Host:\s(\d+\.\d+\.\d+\.\d+)\s(.*)$/m){
                if (defined($ip2name{$1})){
                    my $tmp_ip = $1;
                    if (defined($2) && ($2 =~ m/open/m)){
                        oar_debug("[PingChecker] Good host = $tmp_ip \n");
                        foreach my $i (@{$ip2name{$tmp_ip}}){
                            $good_hosts{$i} = 1;
                        }
                    }
                }
            }
        }
        close(ERROR);
        close(READER);
        waitpid($pid, 0);
        alarm(0);
    };
    oar_debug("[PingChecker] End of command; alarm=$@\n");
    if ($@){
        oar_error("[PingChecker] nmap command times out : it is bad\n");
        return(@hosts);
    }else{
        foreach my $n (@hosts){
            if (!defined($good_hosts{$n})){
                push(@bad_hosts, $n);
            }
        }
        return(@bad_hosts);
    }
}


# use a command which takes the list of nodes in arguments and write on STDERR
# the list of bad nodes
# arg1 --> array of hosts to test
sub generic_hosts(@){
    my @hosts = @_;

    # Get generic command from oar.conf
    init_conf($ENV{OARCONFFILE});
    my $test_cmd = get_conf("PINGCHECKER_GENERIC_COMMAND");
    oar_debug("[PingChecker] command to run : $test_cmd\n");
    my ($cmd, @null) = split(" ",$test_cmd);
    oar_debug("[PingChecker] command to run with arguments : $cmd\n");
    if (!defined($test_cmd) || (! -x $cmd)){
        oar_error("[PingChecker] You want to call a generic test method but PINGCHECKER_GENERIC_COMMAND in oar.conf is not valid\n");
        return(@hosts);
    }

    my %check_test_nodes;
    foreach my $i (@hosts){
        $test_cmd .= " $i";
        $check_test_nodes{$i} = 1;
    }

    my @bad_hosts;
    oar_debug("[PingChecker] $test_cmd \n");
    $ENV{IFS}="";
    $ENV{ENV}="";
    eval {
        my $pid;
        $SIG{ALRM} = sub { kill(9,$pid); die("alarm\n") };
        alarm($Default_timeout);
        $pid = open3(\*WRITER, \*READER, \*ERROR, $test_cmd);
        while(<ERROR>){
            chomp($_);
            #$_ =~ m/^\s*([\w\.]+)\s*$/m;
            $_ =~ m/^\s*([\w\.\-]+)\s*$/m;
            if ($check_test_nodes{$1} == 1){
                oar_debug("[PingChecker] Bad host = $1 \n");
                push(@bad_hosts, $1);
            }
        }
        close(ERROR);
        close(WRITER);
        close(READER);
        waitpid($pid, 0);
        alarm(0);
    };
    oar_debug("[PingChecker] End of command; alarm=$@\n");
    if ($@){
        oar_error("[PingChecker] PINGCHECKER_GENERIC_COMMAND timed out : it is bad\n");
        return(@hosts);
    }else{
        return(@bad_hosts);
    }
}   

return 1;