#!/usr/bin/env perl
# naemon: +epn
# nagios: +epn
# vim: expandtab:ts=4:sw=4:syntax=perl

###################################################
use warnings;
use strict;

BEGIN {
    my $basedir = $ENV{'NAGIOS_PLUGIN'} // $0;
    $basedir    =~ s%/[^/]*$%%gmx;
    $basedir    = $basedir."/..";

    # git version
    if(-d "$basedir/.git" && -e "$basedir/lib/Thruk.pm") {
        unshift @INC, $basedir."/lib";
        if($ENV{'OMD_ROOT'} && !$ENV{'THRUK_CONFIG'}) { $ENV{'THRUK_CONFIG'} = $ENV{'OMD_ROOT'}."/etc/thruk"; }
        if(!$ENV{'THRUK_CONFIG'}) { $ENV{'THRUK_CONFIG'} = $basedir."/"; }
    }

    # omd
    elsif($ENV{'OMD_ROOT'}) {
        unshift @INC, $ENV{'OMD_ROOT'}."/share/thruk/lib";
        if(!$ENV{'THRUK_CONFIG'}) { $ENV{'THRUK_CONFIG'} = $ENV{'OMD_ROOT'}."/etc/thruk"; }
    }

    # pkg installation
    else {
        # not supported yet
    }
};

BEGIN {
    for my $a (@ARGV) {
        if($a eq '-T') {
            $ENV{'THRUK_TIMER'} = 1;
            last;
        }
    }
    use Thruk::Timer qw/timing_breakpoint/;
    &timing_breakpoint('./script/check_thruk_rest');
};

use Thruk::CheckThrukRest;
&timing_breakpoint('modules loaded');
Thruk::CheckThrukRest::_check();
