File: //usr/local/sbin/hp-monitor
#!/usr/bin/env php
<?php
function fmt($domain, $count) {
$domain_width = 30;
$count_width = 10;
$len = $domain_width + $count_width - strlen($domain) - strlen($count);
if ($len < 1) $len = 1;
print $domain;
print str_repeat(' ', $len);
print $count;
print "\n";
}
$file = "/tmp/hp-monitord.sock";
$client = @socket_create(AF_UNIX, SOCK_STREAM, 0) or die ("Cannot create socket!");
@socket_connect($client, $file) or die ("Cannot connect socket! Is hp-monitord running?");
$buffer = "";
while (($buf = socket_read($client, 1024)) != "")
$buffer .= $buf;
$data = json_decode($buffer, true);
foreach ($data as $domain => $count) {
fmt($domain, $count);
}