aboutsummaryrefslogtreecommitdiff
path: root/Sendmail.mib2c
blob: db43f43b6137a438e283b03eef76aca394bf4aa6 (plain)
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
## SNMP Sendmail Statistics Module
## Copyright (C) 2015 Sergey Poznyakoff <gray@gnu.org>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
@startperl@

$vars{'sendmail_translate'} = sub {
    my $name = shift;
    if ($name eq 'queueTotal') {
	$vars{'fn_table'} = 0;
	$vars{'fn_get'} = "get_$name";
    } elsif ($name =~ /^((queue)|(total)|(connection))/) {
	$vars{'fn_table'} = 1;
	$vars{'fn_get'} = "$1_table_get";
    } else {
	$vars{'fn_table'} = 0;
	$vars{'fn_get'} = "get_$name";
    }
    return 0;
};

$vars{agentname} = $vars{name};
$vars{agentname} =~ s/\.pm//; 
$vars{tempfile} = "$vars{agentname}.tmp";

my $oid = new NetSNMP::OID($vars{'oid'});
$vars{rootoid} = '.' . join('.', $oid->to_array());

0;
@endperl@
@open ${tempfile}@
# Hash for all OIDs
@printf "my %soidtable={\n", $@
@foreach $t table@
  @eval $needwalker = 1@   ## Need the walker and checker once this table
  @foreach $c nonindex@    
    @if $c.accessible @
      ##
      ## Generate the entry for the hash table
      ## We first calculate the number of index items for this table
      @eval $numindex = 0@
      @eval $idxelem = ""@
      @foreach $i index@
        @perleval $vars{'idxelem'} .= '.0'; 0; @
        @eval $numindex = $numindex + 1; @
      @end@
    @eval $idxoffset = $c.oidlength@
    "$c.objectID$idxelem" => {
	func     => sub { get_$t('$c', $c.oidlength, @_) },
	type     => $c.type,
	check    => sub { check_$t($c.oidlength, @_) },
        nextoid  => sub { next_$t($c.oidlength, @_) },
	istable  => '1',
	next     => "",
	numindex => $numindex
     },
    @end@
  @end@
@end@
## output the hash with the OIDs and handlers
## Scalars have a single index element
# Scalars
@foreach $s scalar@
  @if $s.accessible@
    @startperl@
    &{$vars{'sendmail_translate'}}($vars{s});
    @endperl@
    '$s.objectID.0' => {
      @if $fn_table@
        func     => sub { $fn_get('$s', @_) },
      @else@
	func     => \&$fn_get,
      @end@
	istable  => 0,
        type     => $s.type,
	next     =>"",
	numindex => 1
    },	
  @end@
@end@
##End of the OID hash
};

## Emit code to register the top level oid with the agent
## The $oid variable comes from mib2c as the last non option arg
# Register the top oid with the agent
my $@agent = new NetSNMP::agent('Name' => '$agentname');
registerAgent($@agent, '$rootoid', $@oidtable);

@close ${tempfile}@
@startperl@
use File::Copy;
use autodie;

print "creating $vars{name}\n";

open(FILE, '>', $vars{name});

print FILE "# THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.\n";

copy($vars{prologue}, \*FILE) if defined $vars{prologue};
copy($vars{tempfile}, \*FILE);
copy($vars{epilogue}, \*FILE) if defined $vars{epilogue};

# Use concatenation to prevent Emacs from handling this as local variables
# block
print FILE "# Local " . "variables:\n";
print FILE "# buffer" . "-read-only: t\n";
print FILE "# End:\n";
print FILE "# vi: set ro:\n";

close FILE;
unlink $vars{tempfile};
0;
@endperl@
    

Return to:

Send suggestions and report system problems to the System administrator.