Skip to content

Instantly share code, notes, and snippets.

@odoucet
Last active September 8, 2015 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoucet/a1fc550a7ccf41ba8bd4 to your computer and use it in GitHub Desktop.
Save odoucet/a1fc550a7ccf41ba8bd4 to your computer and use it in GitHub Desktop.
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