Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard Perfdata Output #7

Closed
distahl opened this issue Apr 17, 2019 · 9 comments
Closed

Standard Perfdata Output #7

distahl opened this issue Apr 17, 2019 · 9 comments

Comments

@distahl
Copy link

distahl commented Apr 17, 2019

Hi,

I'm having issues using this check with InfluxDB and Grafana. I guess it is because of the uncommon perfdata output, which seems to be pnp4nagios specific. Would be great if you could offer an option to output perfdata without all those '::' categories/template-names.

Example:

Current Output: GigabitEthernet4-48::check_snmp::outDiscards=[...]
Wished Output: GigabitEthernet4-48-outDiscards=[...]

And maybe as a bonus :-)
Would be great if I could skip some things of the perfdata like CRC-Errors. Because I already have a check which saves CRC-Errors as perfdata and having them twice will increase my data space unnecessarily.

@dnsmichi
Copy link
Contributor

:: is an extended label format coming from check_multi. Graphite within Icinga 2 supports that by replacing it with a dot, InfluxDB currently does not - there's a discussion in Icinga/icinga2#7060 about this.

@distahl
Copy link
Author

distahl commented Apr 18, 2019

OK, Thank you for the link @dnsmichi .
If I understand you right , you think adding options to this check would only be patchwork, because it doesn't solves the hole root cause. In this case, I guess, I will wait and maybe work with a script wrapper, which changes the output for me :-)

@dnsmichi
Copy link
Contributor

Well, I wouldn't change the perfdata output for this plugin, since there's users which rely on this. Even if that check_multi format is an extension, I know that it is used by many. The main problem is then with handling them in the different metric writers. As said, PNP naturally supports it, Icinga 2 with the Graphite feature parses it, InfluxDB does not. The latter is something where I have little knowledge, that is why we'll need feedback in the linked issue :)

@distahl
Copy link
Author

distahl commented Apr 18, 2019

Well, I wouldn't change the perfdata output for this plugin, since there's users which rely on this

Of course. I was thinking about an option which gives the ability to change the output format.

As said, PNP naturally supports it, Icinga 2 with the Graphite feature parses it, InfluxDB does not. The latter is something where I have little knowledge, that is why we'll need feedback in the linked issue :)

Unfortunately, I'm able to help with this. My knowledge about Influx, is also very small. I'm just lucky it is working nearly out of the box with Icinga and Grafana :-)

@Bierchermuesli
Copy link

interesting - does anyone found a solution how influx can parse the check_multi syntax?

@distahl
Copy link
Author

distahl commented Sep 14, 2020

No. Only thing I did. I have build myself a wrapper script for check_interfaces, which maipulates the the output so influx can read it.

@Bierchermuesli
Copy link

Thanks for reply. are you intend to share your wraper script?

@distahl
Copy link
Author

distahl commented Sep 14, 2020

#!/usr/bin/perl

use strict;
use warnings;
use File::Basename;
#use Data::Dumper qw(Dumper);

my $check_interfaces = '/usr/lib64/nagios/plugins/check_interfaces';
if (-f dirname(__FILE__).'/check_interfaces') {
	$check_interfaces = dirname(__FILE__).'/check_interfaces';
}

if (@ARGV && scalar(@ARGV) > 0) {
	my $args = join("' '", @ARGV);
	my $output = `$check_interfaces '$args'`;
	my $ex = $? >> 8;

	my @out = split(/\n/, $output);
	
	if (!@out || scalar(@out) < 1 || !exists($out[0])) { 
		print $output;
		exit $ex;
	}
	
	my $first = $out[0];
	shift(@out); my $rest = join("\n", @out);
	my @first_parts = split(/\|/, $first);
	
	if (!@first_parts || scalar(@first_parts) < 1) { 
		print $output;
		exit $ex;
	}

	if (!exists($first_parts[0]) || !exists($first_parts[1])) {
		print $output;
		exit $ex;
	}
	
	my $perfdata = $first_parts[1]; $perfdata =~ s/(^\s*|\s*$)//;
	my $out_short = $first_parts[0]; $out_short =~ s/(^\s*|\s*$)//;

	my @labels = split(/\s+/, $perfdata);
	#print Dumper(@labels);
	
	if (!@labels || scalar(@labels) < 1) { 
		print $output;
		exit $ex;
	}

	my $ident = "";
	my $new_perfdata = "";

	foreach (@labels) {
		if ($_ =~ /^interfaces::check_multi::plugins=|time=/) { next; }
		#if ($_ =~ /outCollisions|inCRCs/) { next; }
		if ($_ =~ /::/ ) {
			my @tmp = split(/::/, $_);
			$ident = $tmp[0];
			my $label = $tmp[-1];
			$new_perfdata .= $ident.'-'.$label.' ';
		} else {
			$new_perfdata .= $ident.'-'.$_.' ';
		}
	}

	print $out_short.' | '.$new_perfdata."\n".$rest."\n";
	exit $ex;
} else {
	my $output = `$check_interfaces`;
	my $ex = $? >> 8;
	print $output;
	exit $ex;
}

@RincewindsHat
Copy link
Member

Seems to work with InfluxDB now, at least with the InfluxDB2 writer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants