Projet

Général

Profil

Révision ccf89c4b

IDccf89c4ba2ad27dec4ac75d33f226af94cc8729a
Parent ba4e18a6
Enfant 8b7a1d2a

Ajouté par S. Wefel il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/cirix-netscaler-connections
1
#!/usr/bin/perl
2
# -*- perl -*-
3
# ---------------------------------------------------- #
4
# File : netscaler_conn
5
# Author: Sandro Wefel
6
# based on Script by Damien SIAUD
7
# Date : 05/05/2011
8
# Modified : 05/05/2011
9
# ---------------------------------------------------- #
10
# This script require Net::SNMP
11
#
12
# Netscaler plugin for munin
13
#
14
# License Information:
15
# This program is free software; you can redistribute it and/or modify
16
# it under the terms of the GNU General Public License as published by
17
# the Free Software Foundation; either version 3 of the License, or
18
# (at your option) any later version.
19
#
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
# GNU General Public License for more details.
24
#
25
# You should have received a copy of the GNU General Public License
26
# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
27
#
28
# ---------------------------------------------------- # 
29

  
30
=head1 NAME
31

  
32
netscaler_conn - Munin plugin to monitor netscaler connections
33

  
34
=head1 CONFIGURATION
35

  
36
Make a symlink from netscaler_conn_ to /etc/munin/plugins/netscaler_conn_<nsfqdn>. 
37
You can omit <nsfqdn>, then you need the env variable B<host>.
38

  
39
To configure the plugin, use ENV variables.
40

  
41
Add something lile this to /etc/munin/plugin-conf.d/<conf>
42
 [netscaler_conn_*]
43
 env.community CommunityName
44

  
45
Variables:
46

  
47
=over
48

  
49
=item ENV B<host> netscaler host as FQDN or IP I<default is the nsfqdn-suffix from pluginname>
50

  
51
=item ENV B<port> I<default 161>
52

  
53
=item ENV B<community> I<default "public">
54

  
55
=item ENV B<timeout> in seconds I<default 5>
56

  
57
=back
58

  
59
=head1 AUTHORS
60

  
61
=over
62

  
63
=item Sandro Wefel <wefel@unixos.de>
64

  
65
=item based on scripts by Jimmy Olsen, Damien SIAUD
66

  
67
=back
68

  
69
=head1 LICENSE
70

  
71
GNU General Public License
72

  
73
=head1 MAGIC MARKERS
74

  
75
 #%# family=auto
76
 #%# capabilities=autoconf
77

  
78
=cut
79

  
80
use Net::SNMP;
81

  
82
use Munin::Plugin;
83

  
84
use vars qw($script_name $script_version $o_host $o_community $o_port $o_timeout);
85

  
86
use strict;
87

  
88

  
89
# --------------------------- globals -------------------------- #
90

  
91
$script_name = "netscaler_conn";
92
$script_version = "0.1";
93

  
94
$o_host = undef;
95
$o_community = undef;
96
$o_port = 161;
97

  
98
my $return_str = "";
99

  
100
# ---------------------------- snmp ---------------------------- #
101

  
102
my $oid_prefix = "1.3.6.1.4.1.5951";
103
my $oid_build_version = $oid_prefix.".4.1.1.1.0";
104
my $oid_ssl_session = $oid_prefix.".4.1.1.47.296.0";	# current ssl sessions
105
my $oid_client_conn = $oid_prefix.".4.1.1.46.2.0";	# current client connections
106
my $oid_server_conn = $oid_prefix.".4.1.1.46.1.0";	# current server connections
107

  
108
# ---------------------------- main ----------------------------- #
109

  
110

  
111
my $DEBUG = 0;
112

  
113
my $o_host      = $ENV{host}      || undef;
114
my $o_port      = $ENV{port}      || 161;
115
my $o_community = $ENV{community} || "public";
116
my $o_timeout   = $ENV{timeout}   || 5;
117

  
118
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
119
		print "yes\n";
120
		exit 0;
121
}
122

  
123
if (! defined $o_host ) {
124
	$0 =~ /netscaler_conn_(.+)*$/;
125
	$o_host = $1;
126
	die "No host provided" unless defined $o_host;
127
}
128

  
129
if ($ARGV[0] and $ARGV[0] eq "config") {
130
    print "graph_args --base 1024 -l 0\n";
131
    print "graph_vlabel Connections\n";
132
    print "graph_title Netscaler Connections for $o_host\n";
133
    print "graph_category netscaler\n";
134
    print "graph_period second\n";
135
    print "graph_info This graph shows the netscaler TCP connections.\n";
136
    print "graph_order ",
137
      "client ",
138
		  "server ",
139
		  "ssl ",
140
	    "\n";
141
    print "client.label client\n";
142
    print "client.draw AREA\n";
143
    print "client.info Client connections.\n";
144
    print "server.label server\n";
145
    print "server.draw STACK\n";
146
    print "server.info Server connections.\n";
147
	  print "ssl.label SSL sessions\n";
148
	  print "ssl.draw LINE2\n";
149
  	print "ssl.info Currently active SSL sessions.\n";
150

  
151
    for my $field qw(client server ssl) {
152
        print_thresholds($field);
153
    }
154
    exit 0;
155
}
156

  
157

  
158
my $session = &open_session();
159
if (!defined($session)) {
160
	print "ERROR opening session\n";
161
	exit 1;
162
}
163

  
164
my $counter1;
165
# TCP
166
$counter1 = &get_client_conn($session);
167
$return_str .= "client.value $counter1\n";
168
$counter1 = &get_server_conn($session);
169
$return_str .= "server.value $counter1\n";
170
# SSL
171
$counter1 = &get_ssl_sessions($session);
172
$return_str .= "ssl.value $counter1\n";
173

  
174

  
175
&close_session($session);
176

  
177
print "$return_str"; 
178
exit 0;
179

  
180
# --------------------------- functions ------------------------- #
181

  
182
sub open_session {
183
	my ($sess, $str) = Net::SNMP->session(
184
		-hostname	=> $o_host,
185
		-community	=> $o_community,
186
		-port		=> $o_port,
187
		-timeout	=> $o_timeout
188
	);
189

  
190
	$return_str = $str;
191

  
192
	return $sess;
193
}
194

  
195

  
196
sub close_session {
197
	my ($sess) = @_;
198

  
199
	if(defined($sess)){
200
		$session->close;
201
	}
202
}
203

  
204
sub get_buildversion {
205
	my ($session) = @_;
206
       	my $build_version;
207
	
208
	my $result = $session->get_request(
209
		      -varbindlist => [$oid_build_version]
210
	);
211

  
212
	if (!defined($result)) {
213
		return "na";
214
	}
215
	else {
216
		$build_version = $result->{$oid_build_version};
217
		return"Build version : ".$build_version;
218
	}
219
}
220

  
221
sub get_ssl_sessions {
222
	my ($session) = @_;
223
	my $ssl_session;
224

  
225
	my $result = $session->get_request(
226
		-varbindlist => [$oid_ssl_session]
227
        );
228

  
229
	if (!defined($result)) {
230
		return "na";
231
	}
232
	else {
233
		$ssl_session = $result->{$oid_ssl_session};
234
		return $ssl_session;
235
	}
236
}
237

  
238
sub get_client_conn {
239
	my ($session) = @_;
240
	my $client_conn;
241

  
242
	my $result = $session->get_request(
243
		-varbindlist => [$oid_client_conn]
244
        );
245

  
246
	if (!defined($result)) {
247
		return "na";
248
	}
249
	else {
250
		$client_conn = $result->{$oid_client_conn};
251
		return $client_conn;
252
	}
253
}
254

  
255
sub get_server_conn {
256
	my ($session) = @_;
257
	my $server_conn;
258

  
259
	my $result = $session->get_request(
260
		-varbindlist => [$oid_server_conn]
261
        );
262

  
263
	if (!defined($result)) {
264
		return "na";
265
	}
266
	else {
267
		$server_conn = $result->{$oid_server_conn};
268
		return $server_conn;
269
	}
270
}
271

  

Formats disponibles : Unified diff