Imported Upstream version 0.6.26
This commit is contained in:
@@ -1044,6 +1044,7 @@ sub parse_perfstring {
|
||||
my $check_multi_blockcount = 0;
|
||||
my $multi_parent = cleanup( $NAGIOS{SERVICEDESC} );
|
||||
my $auth_servicedesc = $NAGIOS{DISP_SERVICEDESC};
|
||||
my $seen_multi_label = "";
|
||||
while ($perfstring) {
|
||||
( $perfstring, %p ) = _parse($perfstring);
|
||||
if ( !$p{label} ) {
|
||||
@@ -1052,8 +1053,19 @@ sub parse_perfstring {
|
||||
@perfs = ();
|
||||
last;
|
||||
}
|
||||
|
||||
if ( $p{label} =~ /$seen_multi_label/ ) {
|
||||
# multi label format for each perfdata item (e.g Icinga2)
|
||||
# we're in a sub tree of a multi block, adjust label for further processing
|
||||
my $tmp_prefix = $seen_multi_label."::";
|
||||
$p{label} =~ s/$tmp_prefix//;
|
||||
}
|
||||
|
||||
if ( $p{label} =~ /^[']?([a-zA-Z0-9\.\-_\s\/\#]+)::([a-zA-Z0-9\.\-_\s]+)::([^=]+)[']?$/ ) {
|
||||
@multi = ( $1, $2, $3 );
|
||||
|
||||
$seen_multi_label = $multi[0]."::".$multi[1];
|
||||
|
||||
if ( $count == 0 ) {
|
||||
print_log( "DEBUG: First check_multi block", 3 );
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#!@SHELL@
|
||||
#
|
||||
#
|
||||
### BEGIN INIT INFO
|
||||
# Provides: npcd
|
||||
# Required-Start:
|
||||
# Required-Stop:
|
||||
# Required-Start:
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: @PKG_NAME@ NPCD Daemon Version @PKG_VERSION@
|
||||
@@ -14,7 +14,7 @@
|
||||
#
|
||||
# File : npcd
|
||||
#
|
||||
|
||||
|
||||
servicename=@npcd_name@
|
||||
prefix=@prefix@
|
||||
exec_prefix=${prefix}
|
||||
@@ -47,10 +47,10 @@ printstatus_npcd(){
|
||||
exit 0
|
||||
elif test $? -eq 2; then
|
||||
echo "$servicename is not running but subsystem locked"
|
||||
exit 2
|
||||
exit 3
|
||||
else
|
||||
echo "$servicename is not running"
|
||||
exit 1
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ if [ ! -f $NpcdCfgFile ]; then
|
||||
echo "Configuration file $NpcdCfgFile not found. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# See how we were called.
|
||||
case "$1" in
|
||||
|
||||
@@ -94,7 +94,7 @@ case "$1" in
|
||||
status_npcd
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "$servicename already started..."
|
||||
exit 1
|
||||
exit 0
|
||||
fi
|
||||
echo -n "Starting $servicename:"
|
||||
touch $NpcdRunFile
|
||||
@@ -109,7 +109,7 @@ case "$1" in
|
||||
status_npcd
|
||||
if ! [ $? -eq 0 ]; then
|
||||
echo "$servicename was not running... could not stop"
|
||||
exit 1
|
||||
exit 0
|
||||
fi
|
||||
echo -n "Stopping $servicename: "
|
||||
|
||||
@@ -136,7 +136,7 @@ case "$1" in
|
||||
else
|
||||
echo 'done.'
|
||||
fi
|
||||
rm -f $NpcdLockDir/$NpcdLockFile
|
||||
rm -f $NpcdLockDir/$NpcdLockFile
|
||||
;;
|
||||
|
||||
status)
|
||||
@@ -158,5 +158,5 @@ case "$1" in
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
|
||||
# End of this script
|
||||
|
||||
@@ -49,7 +49,7 @@ my %conf = (
|
||||
);
|
||||
|
||||
Getopt::Long::Configure('bundling');
|
||||
my ( $opt_V, $opt_h, $opt_c, $opt_l, $opt_x, $opt_p );
|
||||
my ( $opt_V, $opt_h, $opt_c, $opt_l, $opt_x, $opt_p, $opt_s, $opt_o, $opt_r );
|
||||
# defaults
|
||||
$opt_x = 1;
|
||||
|
||||
@@ -59,15 +59,22 @@ GetOptions(
|
||||
"c|check_command=s" => \$opt_c,
|
||||
"p|cfg_dir=s" => \$opt_p,
|
||||
"l|list_commands" => \$opt_l,
|
||||
"s|stepwise" => \$opt_s,
|
||||
"x|no_structure_check" => \$opt_x,
|
||||
"o|log_old_xml" => \$opt_o,
|
||||
"d|dry-run" => \$conf{DRY_RUN},
|
||||
"t|tmp_dir=s" => \$conf{TMP_DIR},
|
||||
"force" => \$conf{FORCE},
|
||||
"r|read=s" => \$opt_r,
|
||||
);
|
||||
|
||||
if (defined($opt_r)) {
|
||||
$opt_c = "ALL";
|
||||
}
|
||||
|
||||
print_help() if $opt_h;
|
||||
print_help_opt_p() if !$opt_p;
|
||||
print_help() if !$opt_c and !$opt_l;
|
||||
print_help() if (!$opt_c and !$opt_l) and (!$opt_r);
|
||||
print_version() if $opt_V;
|
||||
|
||||
if($opt_p){
|
||||
@@ -100,14 +107,22 @@ main();
|
||||
|
||||
sub main{
|
||||
check_storage_type();
|
||||
find(\&wanted_xml_files, $conf{RRDPATH});
|
||||
if ($opt_o) {
|
||||
create_dir($conf{TMP_DIR});
|
||||
open(OLDXMLLOG, ">", $conf{TMP_DIR}."/pnp_old_xml_files.list");
|
||||
print OLDXMLLOG "- generated by rrd_convert.pl - \n";
|
||||
print OLDXMLLOG "The following XML files are older than $conf{XML_MAX_AGE} seconds:\n\n";
|
||||
}
|
||||
build_worklist();
|
||||
close(OLDXMLLOG);
|
||||
summary();
|
||||
if($opt_l){ # List commands and exit
|
||||
summary_command_list();
|
||||
exit;
|
||||
}
|
||||
if($#worklist+1 > 0 ){
|
||||
my $answer = read_choice("Start Converter [n|y]?");
|
||||
my $question = "Start converter? " . ($opt_s ? "(Each conversion will be prompted.) " : "");
|
||||
my $answer = read_choice($question . "[n|y]");
|
||||
unless ( $answer =~ m/^y$/i ){
|
||||
print "Exit...\n";
|
||||
exit;
|
||||
@@ -123,7 +138,16 @@ sub main{
|
||||
write_custom_template();
|
||||
my $t0 = [gettimeofday];
|
||||
my $i = 0;
|
||||
my $answered = "";
|
||||
foreach my $xmlfile ( @worklist ) {
|
||||
if($opt_s && ($answered !~ $xmlfile)){
|
||||
my $answer = read_choice("Continue with $xmlfile [n|y]?");
|
||||
unless ( $answer =~ m/^y$/i ){
|
||||
print "Exit... (remember to remove the custom template, if created in this run!)\n";
|
||||
exit;
|
||||
}
|
||||
$answered = $xmlfile;
|
||||
}
|
||||
$i++;
|
||||
undef %ds_list;
|
||||
undef %original_ds_list;
|
||||
@@ -183,43 +207,72 @@ sub check_ds_list{
|
||||
}
|
||||
}
|
||||
|
||||
sub wanted_xml_files{
|
||||
sub build_worklist {
|
||||
if ($opt_r) {
|
||||
process_xml_files($opt_r);
|
||||
close XMLLIST;
|
||||
}else{
|
||||
find(\&find_xml_files, $conf{RRDPATH});
|
||||
}
|
||||
}
|
||||
|
||||
# bulk mode, find all XML files
|
||||
sub find_xml_files{
|
||||
if(m/.xml$/){
|
||||
#printf("File: %s\n",$File::Find::name);
|
||||
my $xmlfile = $File::Find::name;
|
||||
my ($rrdfile) = $xmlfile =~ /^(.*)\.xml$/;
|
||||
$rrdfile .= ".rrd";
|
||||
my $mtime = (stat($xmlfile))[9];
|
||||
if ( $mtime < $max_age ){
|
||||
$stats{old_xml}++;
|
||||
return;
|
||||
}
|
||||
open(XML, $xmlfile);
|
||||
while (<XML>) {
|
||||
if(/TEMPLATE>(.*)</){
|
||||
my ($t) = split("!",$1);
|
||||
push(@commands,$t);
|
||||
if(( defined $opt_c) and ($t =~ /^$opt_c$/)){
|
||||
if( -e $rrdfile ){
|
||||
#print "Found: ".$t." in ".$xmlfile."\n";
|
||||
push(@worklist,$xmlfile);
|
||||
}else{
|
||||
$stats{xml_without_rrd}++;
|
||||
}
|
||||
}elsif(( defined $opt_c) and ($opt_c eq 'ALL')){
|
||||
if( -e $rrdfile ){
|
||||
# Keyword 'ALL' retunrs all XML Files
|
||||
push(@worklist,$xmlfile);
|
||||
}else{
|
||||
$stats{xml_without_rrd}++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
close(XML);
|
||||
xml2worklist($File::Find::name);
|
||||
}
|
||||
}
|
||||
|
||||
# file mode, process file with XML filenames
|
||||
sub process_xml_files{
|
||||
my $xmllist = shift;
|
||||
-r $xmllist or die "Cannot open $xmllist: $!";
|
||||
open XMLLIST, "<$opt_r";
|
||||
foreach (<XMLLIST>) {
|
||||
my $file = $_;
|
||||
chomp($file);
|
||||
m/.xml$/ && xml2worklist($file);
|
||||
}
|
||||
}
|
||||
|
||||
sub xml2worklist {
|
||||
my $xmlfile = shift;
|
||||
my ($rrdfile) = $xmlfile =~ /^(.*)\.xml$/;
|
||||
$rrdfile .= ".rrd";
|
||||
my $mtime = (stat($xmlfile))[9];
|
||||
if ( $mtime < $max_age ){
|
||||
$stats{old_xml}++;
|
||||
if ($opt_o) {
|
||||
print OLDXMLLOG $xmlfile . ": " . scalar localtime($mtime) ."\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
open(XML, $xmlfile);
|
||||
while (<XML>) {
|
||||
if(/TEMPLATE>(.*)</){
|
||||
my ($t) = split("!",$1);
|
||||
push(@commands,$t);
|
||||
if(( defined $opt_c) and ($t =~ /^$opt_c$/)){
|
||||
if( -e $rrdfile ){
|
||||
#print "Found: ".$t." in ".$xmlfile."\n";
|
||||
push(@worklist,$xmlfile);
|
||||
}else{
|
||||
$stats{xml_without_rrd}++;
|
||||
}
|
||||
}elsif (( defined $opt_c) and ($opt_c eq 'ALL') ) {
|
||||
if( -e $rrdfile ){
|
||||
# Keyword 'ALL' retunrs all XML Files
|
||||
push(@worklist,$xmlfile);
|
||||
}else{
|
||||
$stats{xml_without_rrd}++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
close(XML);
|
||||
}
|
||||
|
||||
sub parse_xml_filename{
|
||||
my $xmlfile = shift;
|
||||
$_ = $xmlfile;
|
||||
@@ -327,7 +380,7 @@ sub restore_files(){
|
||||
|
||||
sub backup_rrd_file{
|
||||
my $rrdfile = shift;
|
||||
if ( $conf{RRD_BACKUP} == 1 ){
|
||||
if ( $conf{RRD_BACKUP} == 1 && $conf{'DRY_RUN'} == 0 ){
|
||||
move($rrdfile, $rrdfile.".backup");
|
||||
}
|
||||
}
|
||||
@@ -479,7 +532,7 @@ sub change_config {
|
||||
|
||||
sub check_storage_type{
|
||||
if($conf{'RRD_STORAGE_TYPE'} eq "MULTIPLE"){
|
||||
print "RRD_STORAGE_TYPE is already set to ".$conf{'RRD_STORAGE_TYPE'}."\n";
|
||||
print "RRD_STORAGE_TYPE is already globally set to ".$conf{'RRD_STORAGE_TYPE'}."\n";
|
||||
}
|
||||
}
|
||||
sub check_custom_template {
|
||||
@@ -500,6 +553,8 @@ sub check_custom_template {
|
||||
}
|
||||
|
||||
sub write_custom_template {
|
||||
# do not write custom template in --read mode
|
||||
return if $opt_r;
|
||||
my $command = $opt_c;
|
||||
if ( $conf{DRY_RUN} == 1 ){
|
||||
print "No config check while DRY_RUN = 1\n";
|
||||
@@ -535,8 +590,11 @@ sub print_help{
|
||||
print " [ --dry-run ]\n";
|
||||
print " [ --tmp_dir=<temp directory> ]\n";
|
||||
print " [ --no_structure_check ]\n";
|
||||
print " [ --log_old_xml ]\n";
|
||||
print " [ --stepwise ]\n";
|
||||
print " [ --read=<file with XML filenames> ]\n";
|
||||
print "\n";
|
||||
print "This script is used to switch to RRD_STORAGE_TYPE = MULTIPLE for a given Nagios Check Command\n";
|
||||
print "This script is used to switch to RRD_STORAGE_TYPE = MULTIPLE for all RRDs/a given Nagios Check Command/single RRDs \n";
|
||||
print "More info online http://docs.pnp4nagios.org/pnp-0.6/rrd_convert\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ $no = 1 unless (defined $no);
|
||||
my $ds = `$rrdtool info $rrd | grep '^ds' | grep 'value' | wc -l`;
|
||||
# determine the decimal sign
|
||||
$sign = `$rrdtool info $rrd | grep '^ds' | grep 'value' | tail -1`;
|
||||
($sign) = $sign =~ /.* \d(.)\d+/;
|
||||
($sign) = $sign =~ /.* -?\d(.)\d+/;
|
||||
my $end = ($action eq "insert" ? $ds+$no : $ds);
|
||||
if (($start < 1) or ($start > $ds + 1)) {
|
||||
print "ERROR: number ($start) must be within 1..".($ds+1)."\n";
|
||||
@@ -188,7 +188,7 @@ sub processing {
|
||||
next;
|
||||
}
|
||||
# value enclosed in XML tags
|
||||
if (/<(\S+)>\s+(\S+)\s+</) {
|
||||
if (/<(\S+)>\s*(\S+)\s*</) {
|
||||
$xml{$1} = $2;
|
||||
}
|
||||
next unless ($out);
|
||||
|
||||
Reference in New Issue
Block a user