This file is indexed.

/usr/share/munin/plugins/ifx_concurrent_sessions_ is in munin-plugins-core 2.0.19-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/perl -w
# -*- perl -*-
#

=head1 NAME

ifx_concurrent_sessions_ - Munin wildcard plug-in that connects to
Informix instance and counts number of concurrent sessions from
syssqlstat view of sysmaster of instance.

=head1 APPLICABLE SYSTEMS

Connects over the network to Informix databases.  Uses informix
commands to connect to the databases so these must be present on the
munin-node it runs on.

=head1 CONFIGURATION

As Informix installations can vary wildly the autoconf may fail.
However, it is recommended to let munin-node-configure set the plugin
links by e.g.

   # /usr/sbin/munin-node-configure --families contrib --shell |
     grep concurrent | sh -

Yet, for this plugin to work it is most likely required to grant
select to the user the munin-node runs this plugin as.  This usually
requires to login as user "informix" and execute the following
command:

   $ echo "grant select on syssqlstat to munin as informix" |
     INFORMIXDIR=/path/to/ifx_base INFORMIXSERVER=inst_name dbaccess sysmaster

The value of INFORMIXSERVER usually equals to that of DBSERVERNAME in
the $INFORMIXDIR/etc/onconfig file.

=head1 VERSION

 $Id$

=head1 BUGS

This plugin hangs during autoconf - at least on systems without
informix.  Therefore capabilities magic marker has been removed.

May not autoconfigure correctly as noted above.

=head1 AUTHOR

Contributed by <ralph dot grothe at itdz minus berlin dot de>

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

  #%# family=manual

=cut

use strict;
use File::Find;  # In perl 5 since the start

my @infdir;
if (@ARGV && $ARGV[0] =~ /autoconf|suggest/) {
    # Taint mode requires this
    local $ENV{PATH} = '/bin:/usr/bin';
    # First, try lookup in proc table
    # Note, this will only work if oninit was started with full path
    # On Linux we could easily retreive INFORMIXDIR from /proc by
    # tr \\00 \\012 < /proc/$PID/environ | grep INFORMIXDIR
    # Following ps command should work on Linux and Solaris
    my $pscmd = 'ps -p `pgrep -P1 oninit -d,` -o ppid= -o args=';
    # while HP-UX discerns itself once more
    $pscmd = 'UNIX95= ps -C oninit -o ppid= -o args='
    	if ($^O =~ /hp-?ux/i);
    @infdir = map $_->[1],
	grep $_->[0]==1,
	map [m|(\d+)\s+(\S+)/bin|],
	qx($pscmd);

    # Second, try lookup in filesystem Might also fail if we cannot
    # run find as root However, an oninit binary must exist somewhere
    # but for sanity reasons we restrict find to /opt and /usr. Note,
    # if this aborts with Perl Taint mode errors try removing -T in
    # shebang

    unless (@infdir) {
	no warnings; # to hush single usage of File::Find::name warning
	File::Find::find(sub { -f $_ && -r _ && /^oninit\z/s
				 && push @infdir,
				   $File::Find::name =~ m[(\S+)/bin]},
			 qw(/opt /usr));
    }

    if ($ARGV[0] eq 'autoconf') {
	if (@infdir) {
	    print "yes\n";
	    exit 0;
	}
	else {
	    print "no (Could not find oninit on this host)\n";
	    exit 0;
	}
    }

    if ($ARGV[0] eq 'suggest') {
	# Here we need to retreive INFORMIXSERVER
	# Common Informix installations stick to $INFORMIXDIR/etc/onconfig
	foreach my $dir (@infdir) {
	    local *ONCONFIG;
	    my $onconfig = "$dir/etc/onconfig";
	    next unless -f $onconfig && -r _;
	    open ONCONFIG, $onconfig or die "Couldn't open $onconfig\n";
	    my ($infsrv) = grep /^\s*DBSERVERNAME/sm, <ONCONFIG>;
	    close ONCONFIG;

	    # The directory separator must be replaced by some shell
	    # immune unusual character Note, munin-run (as probably
	    # munin-node) only permit "." as remaining valid character
	    $dir =~ tr,/,.,;

	    # Store INFORMIXDIR and INFORMIXSERVER in the symlink's
	    # basename This releives the user from having to export
	    # these via plugins.conf entries in matching instance
	    # sections but leads to ugly link names
	    print "$dir.$1\n" if $infsrv =~ /DBSERVERNAME\s+(\S+)/;
	}
    }
    exit 0;
}

# Retreive vital Informix environment from plugin's name
@ENV{qw(INFORMIXDIR INFORMIXSERVER)} = $0 =~ /[^.]+(.+)\.(.+)/;
$ENV{INFORMIXDIR} =~ tr,.,/,;
$ENV{PATH} = "$ENV{INFORMIXDIR}/bin";

# Plugin's config section
if (@ARGV && $ARGV[0] =~ /config/i) {
	my $config = qq{
	    graph_title Number of Concurrent Sessions of $ENV{INFORMIXSERVER}
	    graph_category Informix
	    graph_vlabel Number
            graph_info Number of concurrent sessions to $ENV{INFORMIXSERVER}. Note that a constant value of -1 indicates missing grantsfor the plugin user (often "munin") on syssqlstat view.
	    sessions.label Sessions
	    sessions.type GAUGE
	};
	$config =~ s/^\s+//gm;
	print $config;
	exit 0;
}

#printf "%s\n%s\n", @ENV{qw(INFORMIXDIR INFORMIXSERVER)};exit;

# Usually redundant double check
#local *SQLHOSTS;
#my $SQLHOSTS = "$ENV{INFORMIXDIR}/etc/sqlhosts";
#open SQLHOSTS, $SQLHOSTS or die "Cannot open $SQLHOSTS\n";
#my ($infpar) = map [(split /\s+/, $_)[0,2]],
#	       grep /$IFX_INSTT/, <SQLHOSTS>;
#close SQLHOSTS;

#$ENV{INFORMIXSERVER} = $infpar->[0];

# Actual SQL statement to count sessions
# Could be easily replaced by any other valid Sysmaster query to extend plugin

my $query = q{select count(*) from syssqlstat where sqs_dbname != '-';};

local *DBACCESS;
open DBACCESS, "echo \"$query\"|dbaccess sysmaster 2>/dev/null|"
    or die "Cannot open reading pipe from dbaccess\n";
my ($sessions) = grep /^\s*\d+\s*$/sm, <DBACCESS>;
close DBACCESS;

# Of course, we need to subtract our own session. Note, that constant
# output of -1 often indicates lack of select grant on syssqlstat view
# to the user the munin-node runs this plugin as (usually munin)

print 'sessions.value ', $sessions ? --$sessions : 'U', "\n";