#
# Real HTTP monitor

test realhttp {
    static set name "realhttp";
    static set domain realhttp;

    static set description "Monitors a service specified via an URL";
    pernode set seq 1;

    # describe the arguments we accept
    static set arguments
	"url:string:Service URL",
	"timeout:int:Timeout in seconds (default: 8)",
	"user:string:user name (for pages needing authentication, only)",
	"password:string:password (for pages needing authentication only)",
	"maxsize:int:maximum file size (default: 1024)",
	"match:string:regular expression a retrieved file must match (default: none)",
	"nomatch:string:regular expression a retrieved file must not match (default: none)",
	"noredirect:boolean:if true realhttp will not follow redirects (default: true)"
	"extraheaders:string:custom header that should be sent to the server"
	"extraheadersvalue:string:data that should go with extraheader"
	"item:string:column name we should report the results under",
	"perf:int:time in minutes between sending performance data (0 for no performance data)";

    init {
	instance set report_item "http";
	instance set timeout 8;
	instance set maxsize 1024;
	instance import url;
	instance import timeout;
	instance import user;
	instance import password;
	instance import maxsize;
	instance import match;
	instance import nomatch;
	instance import noredirect;
	instance import item report_item;
	instance import perf perf_frequency;
	instance import extraheaders;
	instance import extraheadersvalue;
	# each http monitor within each host gets its unique ID
	instance set id ${seq};
	set seq ${seq} + 1;
    }

    # no discover needed
    discover {
        debug 3 monitoring realhttp ${url};
    }

    monitor {
        set var ${domain};
        debug 6 ${var}.status.${id} ${var}.message.${id} ${var}.time.${id} ${var}.log.${id};
        get ${var}.status.${id} ${var}.message.${id} ${var}.time.${id} ${var}.log.${id};
	instance set status ${${var}.status.${id}};
	instance set message ${${var}.message.${id}};
	instance set time ${${var}.time.${id}};
	instance set log ${${var}.log.${id}};
    }

    report {
        set text ${url} " " ${message} " (" ${time} "s)";
        status red ${status} == 0 "&red " ${text};
        status yellow ${status} == 1 "&yellow " ${text};
        status purple ${status} == 2 "&purple " ${text};
        status green ${status} == 3 "&green " ${text};
	comment "html" "<HR></HR><PRE><strong>" ${url} " header\n\n" </strong> ${log} "</PRE>";
    }

    perf {
        export always realhttp.time.${id}, ${time};
	export sometimes realhttp.url.${id}, ${url};
    }

    pernode unconfigure {
        pernode set seq 1;
    }
}
        
