Monitoring/Sneck/Checks/suricata_flows.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 54 CC 2 SCAR 10.6
CC
2
Cov
0%
check
6.0
option_spec
2.0
defaults
2.0
CRAP 2.9
1 package Monitoring::Sneck::Checks::suricata_flows;
2  
3 use 5.014;
4 use strict;
5 use warnings;
6 use parent 'Monitoring::Sneck::Checks::base';
7 use Check::SuricataFlows ();
8  
9 =head1 NAME
10  
11 Monitoring::Sneck::Checks::suricata_flows - checks Suricata is seeing bi directional flows, through Check::SuricataFlows
12  
13 =head1 VERSION
14  
15 Version 0.3.0
16  
17 =cut
18  
19 our $VERSION = '0.3.0';
20  
21 =head1 SYNOPSIS
22  
23 suricata_flows|perl:suricata_flows
24 suricata_flows|perl:suricata_flows -f /var/log/suricata/flows/current/flow.json -a 20 -w 50
25 suricata_flows|perl:suricata_flows -s sensor1 -s sensor2 -i 192.0.2.1
26  
27 =head1 DESCRIPTION
28  
29 A L<Monitoring::Sneck::Checks> check, for running L<Check::SuricataFlows>
30 in process from sneck, or through sneck_check. It is only of use if
31 L<Monitoring::Sneck::Checks> is installed, which this distribution
32 does not require.
33  
34 It takes the same options as check_suricataflows and works out the
35 status the same way, see L<Check::SuricataFlows> for how flows are read
36 and counted. A flow file that is not there or can not be read is
37 UNKNOWN.
38  
39 The status line has the bi and uni directional counts, followed by the
40 same lines check_suricataflows prints. Perfdata is the bi and uni
41 directional counts, and the bi directional count of each sensor given
42 with -s, as bi_$sensor.
43  
44 =head1 OPTIONS
45  
46 - -f <flows.json> :: The flow EVE JSON file.
47 Default :: /var/log/suricata/flows/current/flow.json
48  
49 - -a <alert count> :: CRITICAL if the bi directional count is this or under.
50 Default :: 10
51  
52 - -w <warn count> :: WARNING if the bi directional count is this or under.
53 Default :: 20
54  
55 - -t <seconds> :: How far back to read, in seconds.
56 Default :: 300
57  
58 - -m <max lines> :: The most lines to read.
59 Default :: 500
60  
61 - -s <sensor> :: A sensor name, from .host, to check for. May be given
62 more than once.
63  
64 - -i <IP> :: A IP whose flows are ignored, as source or destination.
65 May be given more than once.
66  
67 -t is --timeout for every sneck check, so for this one --timeout is the
68 same as -t. It is used only as how far back to read, as nothing is
69 waited on over the network.
70  
71 =cut
72  
73 sub option_spec {
74 return ( 'f=s', 'a=i', 'w=i', 'm=i', 's=s@', 'i=s@' );
75 }
76  
77 # match Check::SuricataFlows, so perfdata has them
78 sub defaults { return { a => 10, w => 20 } }
79  
80 =head1 METHODS
81  
82 =head2 check
83  
84 Does the check.
85  
86 =cut
87  
88 sub check {
89 my ($self) = @_;
90  
91 my $sensors = $self->opt('s') // [];
92  
93 # new dies on bad options, which is UNKNOWN
94 my $results = Check::SuricataFlows->new(
95 flow_file => $self->opt('f'),
96 alert_count => $self->opt('a'),
97 warn_count => $self->opt('w'),
98 read_back_time => $self->opt('timeout'),
99 max_lines => $self->opt('m'),
100 sensor_names => $sensors,
101 ignore_IPs => $self->opt('i') // [],
102 )->run;
103  
104 my @lines = split( /\n/, $results->{status} );
105 if ( $results->{status_code} == 3 ) {
106 return $self->finish( $self->UNKNOWN, join( ', ', @lines ) );
107 }
108  
109 # the counts alert at or under, so as ranges, alert under one more
110 my ( $warning, $critical ) = ( ( $self->opt('w') + 1 ) . ':', ( $self->opt('a') + 1 ) . ':' );
111 $self->perfdata(
112 label => 'bi',
113 value => $results->{bi_directional_count},
114 warning => $warning,
115 critical => $critical,
116 min => 0
117 );
118 $self->perfdata( label => 'uni', value => $results->{uni_directional_count}, min => 0 );
119 foreach my $sensor ( @{$sensors} ) {
120 $self->perfdata(
121 label => 'bi_' . $sensor,
122 value => $results->{by_sensor}{$sensor}{bi_directional_count} // 0,
123 warning => $warning,
124 critical => $critical,
125 min => 0
126 );
127 }
128  
129 return $self->finish(
130 $results->{status_code},
131 $results->{bi_directional_count}
132 . ' bi directional, '
133 . $results->{uni_directional_count}
134 . ' uni directional flows',
135 @lines
136 );
137 } ## end sub check
138  
139 =head1 AUTHOR
140  
141 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
142  
143 =head1 LICENSE AND COPYRIGHT
144  
145 This software is Copyright (c) 2026 by Zane C. Bowers-Hadley.
146  
147 This is free software, licensed under:
148  
149 The GNU General Public License, Version 2, June 1991
150  
151 =cut
152  
153 1;