I updated my code and have come a little closer to figuring out the issue. When I run this script from the command prompt it returns the expected information, how ever, in Nagios it does not recognize anything sent to it by the array. I tested this by assigning the value of the array to a variable and then sending it to output. The command line prints 4, but nagios prints 0. I am at a loss here Here's the code
#!/usr/bin/perl use warnings; use strict; use POSIX qw(strftime); use Date::Calc qw(Delta_Days); my $domainList = 'domains.txt'; my (@display, $stat, $expDate, $daysLeft, $diff, $spec, $len); my $date = strftime "%Y-%m-%d", localtime; my $flag = 0; open (FILE, $domainList); my @dom = <FILE>; foreach my $dm (@dom) { chomp $dm; $stat = `whois $dm | egrep "Registrar Registration Expiration Date +|Registry Expiry Date"`; $stat =~ m/(\d{4}-\d{2}-\d{2})/; $expDate = $1; $diff = &dateDiff($expDate); $len = length($dm); if ($len <= 7) { $spec = $dm."\t\t\t".$diff; } if ($len > 7 && $len <=16) { $spec = $dm."\t\t".$diff; } if ($len > 16) { $spec = $dm."\t".$diff; } if ($diff < 28 && $diff > 14) { $flag = 1; } if ($diff <= 14) { $flag = 2; } push @display, "$spec"; } close FILE; if ($flag == 2) { my $status = "CRIT: There are Certificates Expiring Soon. Please +Resolve"; unshift @display, $status; print join("\n",@display); exit 2; } if ($flag == 1) { my $status = "WARN: There are Certificates Expiring within a month +. Please Resolve"; unshift @display, $status; print join("\n",@display); exit 1; } else { my $status = "OK: Certificates Look good"; unshift @display, $status; print join("\n",@display); exit 0; } sub dateDiff { my $ex = $_[0]; $ex =~ m/(\d{4})-(\d{2})-(\d{2})/; my $y = $1; my $m = $2; my $d = $3; my @exDate = ($y, $m, $d); $date =~ m/(\d{4})-(\d{2})-(\d{2})/; my $yLoc = $1; my $mLoc = $2; my $dLoc = $3; my @curDate = ($yLoc, $mLoc, $dLoc); my $diffSub = Delta_Days(@curDate, @exDate); return($diffSub); }

In reply to Nagios custom Perl check by edimusrex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.