#!/usr/bin/perl -w
#########################################################
## TruePath Technologies Inc.
#########################################################
## Web: http://www.TruePathTechnologies.com/
## Support: tickets@truepathtechnologies.com
## Phone: 585.672.5481
#########################################################
## This code is designed, written, and maintained by
## TruePath Technologies Inc. Do not use, modify or
## distribute this code in any way without first getting
## written persmission from TruePath Technologies Inc.
#########################################################
## Coding Header v2.45
#########################################################
#####
###
## $Header$
###
###### ver. $Revision$
## arg1 = image file
## arg2 = vertical height
## arg3 = horizontal height
## if only image file provided then default size vals of 1x1 are used

use strict;
use utils qw ( %ERRORS );

sub check_image{
`wget --no-check-certificate $ARGV[0] -O /tmp/myimg$$.png > /dev/null 2>&1`;
if( -s "/tmp/myimg$$.png" ){#$? == 0 ){
        my $fileOutput = `file /tmp/myimg$$.png`;
        my @outputSplit1 = split(/,/,$fileOutput);
        my @outputSplit2 = split(/ /,$outputSplit1[1]);
        if( $#ARGV >= 2 ){ # if params for height and width are supplies
                if( $outputSplit2[1] == $ARGV[1] && $outputSplit2[3] == $ARGV[2] ){
                        print "OK - Dimensions:@outputSplit2\n";
                        exit $ERRORS{'OK'};
                }
                else{
                        print "CRITICAL - Dimensions do not match. Expected: $ARGV[1] x $ARGV[2] Actual:@outputSplit2\n";
                        exit $ERRORS{'CRITICAL'};
                }
        }
        else{ # if no parms for height and width then defualt vals of 1x1 used
                if( $outputSplit2[1] == 1 && $outputSplit2[3] == 1 ){
                        print "CRITICAL - Dimensions:@outputSplit2\n";
                        exit $ERRORS{'CRITICAL'};
                }
                else{
                        print "OK - Dimensions:@outputSplit2\n";
                        exit $ERRORS{'OK'};
                }
        }
}
else{
        print "Unknown Error.\n";
        exit $ERRORS{'UNKNOWN'};}
}

check_image(@ARGV);
