fix hostnames with dashes
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 12 Dec 2016 06:43:40 +0000 (07:43 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 12 Dec 2016 06:43:40 +0000 (07:43 +0100)
atop2influx.pl

index 1bb781b..19f0768 100755 (executable)
@@ -21,7 +21,7 @@ sub update_time {
 }
 
 my $tags = $ENV{TAGS};
 }
 
 my $tags = $ENV{TAGS};
-$tags = ",$tags" unless $tags =~ m/^,/;
+$tags = ",$tags" if $tags && $tags !~ m/^,/;
 
 while(<>) {
        chomp;
 
 while(<>) {
        chomp;
@@ -31,7 +31,7 @@ while(<>) {
 
        my @vals;
 
 
        my @vals;
 
-       if ( /^(\w+)\s+(\d+\S+)\s+(.+)\s+(\w+)\s+(\d\d\d\d)\/(\d\d)\/(\d\d)$/ ) {
+       if ( /^([\w\-]+)\s+(\d+\S+)\s+(.+)\s+(\w+)\s+(\d\d\d\d)\/(\d\d)\/(\d\d)$/ ) {
                $host = $1;
                @cols = qw( kernel build arch );
                @vals =   ( qq{"$2"}, qq{"$3"}, qq{"$4"} ); # must quote all this as strings for influx
                $host = $1;
                @cols = qw( kernel build arch );
                @vals =   ( qq{"$2"}, qq{"$3"}, qq{"$4"} ); # must quote all this as strings for influx
@@ -55,7 +55,7 @@ while(<>) {
        } elsif ( m/^\s+(.+)/ ) {
                @vals = split(/\s+/, $1);
        } else {
        } elsif ( m/^\s+(.+)/ ) {
                @vals = split(/\s+/, $1);
        } else {
-               die "UNPARSED: $_\n";
+               warn "UNPARSED: $_\n";
        }
 
        next unless @vals;
        }
 
        next unless @vals;
@@ -63,7 +63,7 @@ while(<>) {
        next if $measurement =~ /top3/; # FIXME this isn't parsed yet
 
        #XXX { cols => \@cols, vals => \@vals };
        next if $measurement =~ /top3/; # FIXME this isn't parsed yet
 
        #XXX { cols => \@cols, vals => \@vals };
-       print "atop_$measurement,host=$host$tags";
+       print "$measurement,host=$host$tags";
        my $d = " ";
        foreach my $i ( 0 .. $#cols ) {
                if ( my $c = $cols[$i] ) {
        my $d = " ";
        foreach my $i ( 0 .. $#cols ) {
                if ( my $c = $cols[$i] ) {