Révision 17f78427
Whitespace cleanup
- remove trailing whitespace
- remove empty lines at the end of files
| plugins/ntp/ntp_peers | ||
|---|---|---|
| 39 | 39 |
# |
| 40 | 40 |
# Change log |
| 41 | 41 |
# v1.0.0 2008-07-21 Chris Hastie |
| 42 |
# initial release
|
|
| 42 |
# initial release |
|
| 43 | 43 |
# |
| 44 | 44 |
# v1.1.0 2010-12-07 Uffe Norberg |
| 45 | 45 |
# - Changed default statedir to /var/lib/munin/plugin-state (Debian default) |
| ... | ... | |
| 107 | 107 |
while (<SERVICE>) {
|
| 108 | 108 |
if (/^[-+*#](\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\s+\S+){7}\s+(\S+)/) {
|
| 109 | 109 |
my $name = &lookupname($1); |
| 110 |
$peers{$1}{'value'} = $3;
|
|
| 110 |
$peers{$1}{'value'} = $3;
|
|
| 111 | 111 |
} |
| 112 | 112 |
} |
| 113 | 113 |
close(SERVICE); |
| ... | ... | |
| 140 | 140 |
# save list of peer IPs and hostnames |
| 141 | 141 |
if(-l $statefile) {
|
| 142 | 142 |
die("$statefile is a symbolic link, refusing to touch it.");
|
| 143 |
}
|
|
| 143 |
} |
|
| 144 | 144 |
open (OUT, ">$statefile") or exit 4; |
| 145 | 145 |
foreach my $i (keys %peers) {
|
| 146 | 146 |
print OUT "$i:" . $peers{$i}{'name'} . "\n";
|
| ... | ... | |
| 155 | 155 |
# create a valid munin field name from the hostname |
| 156 | 156 |
sub sanitize_field () {
|
| 157 | 157 |
my $field = shift; |
| 158 |
|
|
| 158 |
|
|
| 159 | 159 |
# replace illegal characters with an underscore |
| 160 | 160 |
$field =~ s/[^A-Za-z0-9_]/_/g; |
| 161 | 161 |
# prepend an underscore if name starts with a number |
| 162 | 162 |
$field =~ s/^([^A-Za-z_])/_$1/; |
| 163 |
|
|
| 163 |
|
|
| 164 | 164 |
# truncate to 19 characters |
| 165 | 165 |
if (length($field) > 19) {
|
| 166 | 166 |
$field = substr($field, 0, 19); |
| ... | ... | |
| 181 | 181 |
my $ip = shift; |
| 182 | 182 |
# have we already got it? |
| 183 | 183 |
if ($peers{$ip}{'name'}) {
|
| 184 |
return $peers{$ip}{'name'};
|
|
| 184 |
return $peers{$ip}{'name'};
|
|
| 185 | 185 |
} |
| 186 | 186 |
# else look it up |
| 187 |
my $iaddr = inet_aton($ip);
|
|
| 188 |
my $name = gethostbyaddr($iaddr, AF_INET) || $ip;
|
|
| 187 |
my $iaddr = inet_aton($ip); |
|
| 188 |
my $name = gethostbyaddr($iaddr, AF_INET) || $ip; |
|
| 189 | 189 |
# add to cache |
| 190 | 190 |
$peers{$ip}{'name'} = $name;
|
| 191 | 191 |
return $name; |
Formats disponibles : Unified diff