
<sampler name="LinuxCertCheck">
	<sampleInterval>
		<data>43200</data>
	</sampleInterval>
	<plugin>
		<toolkit>
			<samplerScript>
				<data>./ChkCert.sh www.itrsgroup.com support.itrsgroup.com www.example.com</data>
			</samplerScript>
			<script>
				<contents>
					<data>#!/bin/bash
#set -x #for Debugging
#typical port for cert checking/https calls
cport=443
if [ $# -gt 0 ];
then
    #Setup your headlines.
    echo &quot;Host, Issuer, Subject, Status, Expires On, Days Left&quot;
     
    #Check the OS just in case
    if [[ `uname` -eq &quot;Linux&quot; ]];
    then
        for var in &quot;$@&quot;
    do   
        Conn=$(echo | openssl s_client -connect $var:$cport -servername $var 2&gt;/dev/null | openssl x509 -noout -issuer -subject -dates 2&gt;&amp;1)
        ConnCheck=$(echo &quot;$Conn&quot; | grep &quot;unable to load certificate&quot;)
 
        if [ &quot;$ConnCheck&quot; == &quot;unable to load certificate&quot; ];
        then
        echo &quot;$var, ---, ---, Invalid/Can Not Connect, ---, ---&quot;
        else
        Subj=$(echo &quot;$Conn&quot; | grep &quot;subject=&quot; | sed -e &quot;s/subject=//g&quot; | sed -e &quot;s/\// /g&quot; | sed -e &quot;s/,//g&quot;)
        Issuer=$(echo &quot;$Conn&quot; | grep &quot;issuer=&quot; | sed -e &quot;s/issuer=//g&quot;| sed -e &quot;s/\// /g&quot; | sed -e &quot;s/,//g&quot;)
        ExpDate=$(echo &quot;$Conn&quot; | grep &quot;notAfter=&quot; | sed -e &quot;s/notAfter=//g&quot;)
        EpocExpDate=$(date --date=&quot;$ExpDate&quot; +%s)
        EpocToday=$(date +%s)
        SecLeft=$(($EpocExpDate - $EpocToday))
        DaysLeft=$(( $SecLeft / 86400 ))
        echo &quot;$var,$Issuer,$Subj,Valid,$ExpDate,$DaysLeft&quot;
        fi               
    done   
    fi
fi</data>
				</contents>
				<filename>
					<data>ChkCert.sh</data>
				</filename>
			</script>
		</toolkit>
	</plugin>
</sampler>