diff options
author | Mohit Mehta <mohit.mehta@vyatta.com> | 2008-08-09 11:52:33 +0000 |
---|---|---|
committer | Mohit Mehta <mohit.mehta@vyatta.com> | 2008-08-09 11:52:33 +0000 |
commit | fd255fe92ff63534dd8a61df0466f8c52abe6fdd (patch) | |
tree | 7dd2e02fab0b7f8ebea876b684e28a519fc3bb34 | |
parent | 66222be044d65fe045d4148ddf4eb5d178294150 (diff) | |
download | vyatta-op-fd255fe92ff63534dd8a61df0466f8c52abe6fdd.tar.gz vyatta-op-fd255fe92ff63534dd8a61df0466f8c52abe6fdd.zip |
dns-forwarding op-mode commands:
'clear dns forwarding cache'
'show dns forwarding statistics'
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | scripts/vyatta-op-dns-forwarding.pl | 117 | ||||
-rw-r--r-- | templates/clear/dns/forwarding/cache/node.def | 2 | ||||
-rw-r--r-- | templates/show/dns/forwarding/nameservers/node.def | 2 | ||||
-rw-r--r-- | templates/show/dns/forwarding/node.def | 1 | ||||
-rw-r--r-- | templates/show/dns/forwarding/statistics/node.def | 8 | ||||
-rw-r--r-- | templates/show/dns/node.def | 1 |
7 files changed, 131 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 7499a22..1063b78 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,6 +21,7 @@ bin_SCRIPTS += scripts/vyatta-tshark-interface-port.pl bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh bin_sudo_users_SCRIPTS += scripts/vyatta-reboot.pl +bin_sudo_users_SCRIPTS += scripts/vyatta-op-dns-forwarding.pl cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \ cpio -0pd diff --git a/scripts/vyatta-op-dns-forwarding.pl b/scripts/vyatta-op-dns-forwarding.pl new file mode 100644 index 0000000..d23ae7f --- /dev/null +++ b/scripts/vyatta-op-dns-forwarding.pl @@ -0,0 +1,117 @@ +#!/usr/bin/perl +# +# Module: vyatta-op-dns-forwarding.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Mohit Mehta +# Date: August 2008 +# Description: Script to execute op-mode commands for DNS forwarding +# +# **** End License **** +# + +use lib "/opt/vyatta/share/perl5/"; +use Getopt::Long; +use VyattaConfig; +use strict; +use warnings; + +my $show_stats_output=""; +my $show_nameservers_output=""; +my $dnsmasq_log='/var/log/dnsmasq.log'; + +sub get_cache_stats { + my ($cache_size, $queries_forwarded, $queries_answered_locally, $entries_inserted, $entries_removed); + + my $grepped_line = `grep 'cache size' $dnsmasq_log`; + my @split_line = split(/\s+/, $grepped_line); + my @temp_split = split(/,/, $split_line[6]); + $cache_size = $temp_split[0]; + @temp_split = split(/\//, $split_line[7]); + $entries_removed = $temp_split[0]; + $entries_inserted = $temp_split[1]; + + $grepped_line = `grep 'queries forwarded' $dnsmasq_log`; + @split_line = split(/\s+/, $grepped_line); + @temp_split = split(/,/, $split_line[6]); + $queries_forwarded = $temp_split[0]; + $queries_answered_locally = $split_line[10]; + + $show_stats_output .= "----------------\n"; + $show_stats_output .= "Cache statistics\n"; + $show_stats_output .= "----------------\n"; + $show_stats_output .= "Cache size: $cache_size\n"; + $show_stats_output .= "Queries forwarded: $queries_forwarded\n"; + $show_stats_output .= "Queries answered locally: $queries_answered_locally\n"; + $show_stats_output .= "Total DNS entries inserted into cache: $entries_inserted\n"; + $show_stats_output .= "DNS entries removed from cache before expiry: $entries_removed\n"; + +} + +sub get_nameserver_stats { + + $show_stats_output .= "\n---------------------\n"; + $show_stats_output .= "Nameserver statistics\n"; + $show_stats_output .= "---------------------\n"; + + my @grepped_lines = `grep 'server' $dnsmasq_log`; + + foreach my $lines (@grepped_lines) { + my @each_line = split(/\s+/, $lines); + my $nameserver_word = $each_line[5]; + my @nameserver_split = split(/#/, $nameserver_word); + my $nameserver = $nameserver_split[0]; + my $queries_sent_word = $each_line[8]; + my @queries_sent_split = split(/,/, $queries_sent_word); + my $queries_sent = $queries_sent_split[0]; + my $queries_retried_failed = $each_line[12]; + + $show_stats_output .= "Server: $nameserver\nQueries sent: $queries_sent\nQueries retried or failed: $queries_retried_failed\n\n"; + + } +} + +sub print_stats { + print $show_stats_output; +} + +# +# main +# +my ($clear_cache, $show_statistics, $show_nameservers); + +GetOptions("clear-cache!" => \$clear_cache, + "show-statistics!" => \$show_statistics, + "show-nameservers!" => \$show_nameservers); + +if (defined $clear_cache) { + system("kill -1 `pidof dnsmasq`"); +} + +if (defined $show_statistics) { + system("echo > /var/log/dnsmasq.log; kill -10 `pidof dnsmasq`"); + get_cache_stats; + get_nameserver_stats; + print_stats; +} + +if (defined $show_nameservers) { + +} + +exit 0; + +# end of file diff --git a/templates/clear/dns/forwarding/cache/node.def b/templates/clear/dns/forwarding/cache/node.def index 8211e12..8a5f8cc 100644 --- a/templates/clear/dns/forwarding/cache/node.def +++ b/templates/clear/dns/forwarding/cache/node.def @@ -2,7 +2,7 @@ help: Clear DNS forwarding cache run: if ps ax | grep dnsmasq | grep -v grep > /dev/null then - kill -1 `pidof dnsmasq` + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dns-forwarding.pl --clear-cache else echo "DNS forwarding not configured" fi diff --git a/templates/show/dns/forwarding/nameservers/node.def b/templates/show/dns/forwarding/nameservers/node.def new file mode 100644 index 0000000..0609f6a --- /dev/null +++ b/templates/show/dns/forwarding/nameservers/node.def @@ -0,0 +1,2 @@ +help: Show DNS forwarding nameservers information +run: sudo /opt/vyatta/bin/sudo-users/vyatta-op-dns-forwarding.pl --show-nameservers diff --git a/templates/show/dns/forwarding/node.def b/templates/show/dns/forwarding/node.def new file mode 100644 index 0000000..eb9ce4b --- /dev/null +++ b/templates/show/dns/forwarding/node.def @@ -0,0 +1 @@ +help: Show DNS forwarding information diff --git a/templates/show/dns/forwarding/statistics/node.def b/templates/show/dns/forwarding/statistics/node.def new file mode 100644 index 0000000..a73b49d --- /dev/null +++ b/templates/show/dns/forwarding/statistics/node.def @@ -0,0 +1,8 @@ +help: Show DNS forwarding statistics +run: + if ps ax | grep dnsmasq | grep -v grep > /dev/null + then + sudo /opt/vyatta/bin/sudo-users/vyatta-op-dns-forwarding.pl --show-statistics + else + echo "DNS forwarding not configured" + fi diff --git a/templates/show/dns/node.def b/templates/show/dns/node.def new file mode 100644 index 0000000..45d0e4f --- /dev/null +++ b/templates/show/dns/node.def @@ -0,0 +1 @@ +help: Show Domain Name Server (DNS) information |