Last active
September 8, 2015 13:36
-
-
Save odoucet/a1fc550a7ccf41ba8bd4 to your computer and use it in GitHub Desktop.
Named statistics parser into CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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