aboutsummaryrefslogtreecommitdiff
path: root/src/varnish_mib.mib2c
blob: 6be8cd77ceb15f613029aa6bf1f0069c61be6fb6 (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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# This file is part of varnish-mib -*- c -*-
# Copyright (C) 2014 Sergey Poznyakoff
#
# Varnish-mib 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.
#
# Varnish-mib 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 varnish-mib.  If not, see <http://www.gnu.org/licenses/>.

# This macro inserts a comment instructing Emacs and vi that
# this file is read-only.  It must be called at the end of the file.	
@define ROCOM@
/* Local variables:
   buffer-read-only: t
   End:
   vi: set ro:
*/
@enddefine@
@open ${name}@
/* THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT. */

#include "varnish_mib.h"

static struct VSM_data *vd;

void
varnish_snmp_init(void)
{
    vd = VSM_New();

    if (VSM_Open(vd))
        exit(1);
}

void
varnish_snmp_deinit(void)
{
    VSM_Close(vd);
}

@startperl@
$vars{'varnish_translate'} = sub {
    my $name = shift;
    my %trans = (
	clientAcceptedConnections => [ 'MAIN', 'sess_conn' ],
	clientRequestsReceived    => [ 'MAIN', 'client_req' ],
	clientCacheHits           => [ 'MAIN', 'cache_hit' ],
	clientCacheHitsPass       => [ 'MAIN', 'cache_hitpass' ],
	clientCacheMisses         => [ 'MAIN', 'cache_miss' ],
	clientBan                 => [ 'STRING', '',
				       { varnish_set_action => 'varnish_ban' }  ],
	backendConnSuccess        => [ 'MAIN', 'backend_conn' ],
	backendConnNotAttempted   => [ 'MAIN', 'backend_unhealthy' ],
	backendConnToMany         => [ 'MAIN', 'backend_busy' ],
	backendConnFailures       => [ 'MAIN', 'backend_fail' ],
	backendConnReuses         => [ 'MAIN', 'backend_reuse' ],
	backendConnRecycled       => [ 'MAIN', 'backend_recycle' ],
	backendConnUnused         => [ 'MAIN', 'backend_toolate' ],
	totalSessions             => [ 'MAIN', 's_sess' ],
	totalRequests             => [ 'MAIN', 's_req' ],
	totalPipe                 => [ 'MAIN', 's_pipe' ],
	totalPass                 => [ 'MAIN', 's_pass' ],
	totalFetch                => [ 'MAIN', 's_fetch' ],
	totalHeaderBytes          => [ 'MAIN', 's_req_hdrbytes' ],
	totalBodyBytes            => [ 'MAIN', 's_req_bodybytes' ]
	);

    my $r = $trans{$name};
    if (!defined($r)) {
	print STDERR "no translation for $name!\n";
	exit(1);
    }

    $vars{'varnish_type'} = $r->[0];
    $vars{'varnish_member'} = $r->[1];
    my $setkw = qw(varnish_set_reserve2 varnish_set_free varnish_set_action
		   varnish_set_commit varnish_set_undo);
    if ($#{$r} == 2) {
	@vars{keys %{$r->[2]}} = values %{$r->[2]};
    } else {
	delete $vars{$setkw};
    }
    return 0;
};

$vars{'modulename'} = $vars{'name'};
$vars{'modulename'} =~ s#.*/##;
$vars{'modulename'} =~ s/\.c$//;
print "$vars{'modulename'}\n";

0;
@endperl@

/* Variable handlers.

   An instance handler only hands us one request at a time, unwrapping
   any eventual GETNEXT requests.  All OIDs are read-only, so the handlers
   should only handle GET requests.
*/

@foreach $i scalar@
static int
handle_$i(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
  @if $i.settable@
    int ret;
  @end@
    
  @startperl@
    &{$vars{'varnish_translate'}}($vars{'i'});
  @endperl@
      
    if (VSM_Abandoned(vd)) {
        DEBUGMSGTL(("$modulename", "reopening vd\n"));
	VSM_Close(vd);
	VSM_Open(vd);
    }
  
    switch(reqinfo->mode) {
    case MODE_GET:
  @if $varnish_type eq 'MAIN'@
    {			    
        struct VSC_C_main const *st = VSC_Main(vd, NULL);
	if (!st)
	    return SNMP_ERR_NOSUCHNAME;
	snmp_set_var_typed_value(requests->requestvb, $i.type,
				 &st->$varnish_member,
				 sizeof(st->$varnish_member));
    }
  @elsif $varnish_type eq 'STRING'@
    {
	const char *s = "$varnish_member";
	snmp_set_var_typed_value(requests->requestvb, $i.type,
				 s, strlen(s));
    }
  @else@
    @printf "unrecognized type %s for %s" $varnish_type $i@
  @end@
        break;

  @if $i.settable@
    /*
     * SET REQUEST
     *
     * multiple states in the transaction.  See:
     * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
     */
    case MODE_SET_RESERVE1:
	/* or you could use netsnmp_check_vb_type_and_size instead */
	ret = netsnmp_check_vb_type(requests->requestvb, $i.type);
        if (ret != SNMP_ERR_NOERROR)
	    netsnmp_set_request_error(reqinfo, requests, ret);
	break;

    case MODE_SET_RESERVE2:
    @if $varnish_set_reserve2 ne ''@
        if ($varnish_set_reserve2 (reqinfo, requests, vd)) {
	    netsnmp_set_request_error(reqinfo, requests,
				      SNMP_ERR_RESOURCEUNAVAILABLE);
	}
    @end@
	break;

    case MODE_SET_FREE:
    @if $varnish_set_free ne ''@
        # Free resources allocated in RESERVE1 and/or
	# RESERVE2.  Something failed somewhere, and the states
	# below won't be called. */
        $varnish_set_free(reqinfo, requests, vd);
    @end@
	break;

    case MODE_SET_ACTION:
    @if $varnish_set_action ne ''@
        ret = $varnish_set_action(reqinfo, requests, vd);
        if (ret != SNMP_ERR_NOERROR)
	    netsnmp_set_request_error(reqinfo, requests, ret);
    @end@
	break;

    case MODE_SET_COMMIT:
    @if $varnish_set_commit ne ''@
	# delete temporary storage
        if ($varnish_set_commit(reqinfo, requests, vd))
	    netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
    @end@
	break;

    case MODE_SET_UNDO:
    @if $varnish_set_undo ne ''@
	# UNDO and return to previous value for the object
        if ($varnish_set_undo(reqinfo, requests, vd))
	    netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
    @end@
	break;
  @end@

    default:
	/* we should never get here, so this is a really bad error */
	snmp_log(LOG_ERR, "unknown mode (%d) in handle_${i}\n", reqinfo->mode );
	return SNMP_ERR_GENERR;
    }
    
    return SNMP_ERR_NOERROR;
}
@end@

/** Initializes the $name module */
void
init_$modulename(void)
{
  @foreach $i scalar@
    const oid ${i}_oid[] = { $i.commaoid };
  @end@

  DEBUGMSGTL(("$modulename", "Initializing\n"));

  @foreach $i scalar@
    netsnmp_register_scalar(
        netsnmp_create_handler_registration("$i", handle_$i,
                               ${i}_oid, OID_LENGTH(${i}_oid),
    @if !$i.settable@
                               HANDLER_CAN_RONLY
    @end@
    @if $i.settable@
                               HANDLER_CAN_RWRITE
    @end@
        ));
  @end@
    varnish_snmp_init();
}

void
deinit_$modulename(void)
{
    varnish_snmp_deinit();
}
@calldefine ROCOM@

Return to:

Send suggestions and report system problems to the System administrator.