Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Named statistics parser into CSV
<?php
$fp = fopen('/etc/named/named.stats', 'r');
$data = array();
$start = false;
$currentHost = '';
while($line = fgets($fp, 1024)) {
if (strpos($line, 'Per Zone Query Statistics ') !== false) {
$start = true;
}
if ($start === false) {
continue;
} elseif (preg_match('@^\[(.*)\]$@', trim($line), $preg)) {
$currentHost = $preg[1];
$data[$currentHost] = array();
} elseif (preg_match('@^([0-9]{1,}) queries resulted in (.*)$@', trim($line), $preg)) {
$data[$currentHost][$preg[2]] = $preg[1];
} else {
}
}
fclose($fp);
echo "Domaine\tHits DNS\n";
foreach ($data as $name => $vals) {
if (!isset($vals['successful answer'])) continue;
// here change what you want. Here, only successfull answers.
echo $name."\t".$vals['successful answer']."\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.