aboutsummaryrefslogtreecommitdiff
path: root/src/varnish_mib.mib2c
blob: 55b57e515dba7a1f89487a65bef191f168d267a0 (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
# 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/>.
@open ${name}@
/*
 * Note: this file originally auto-generated by mib2c using
 * mib2c.varnish.conf  
 */

#include <config.h>
#include <stdlib.h>
#include <stdint.h>

#include "vapi/vsc.h"
#include "vapi/vsm.h"

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.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 => 'sess_conn',
	clientRequestsReceived    => 'client_req',
	clientCacheHits           => 'cache_hit',
	clientCacheHitsPass       => 'cache_hitpass',
	clientCacheMisses         => 'cache_miss',
	backendConnSuccess        => 'backend_conn',
	backendConnNotAttempted   => 'backend_unhealthy',
	backendConnToMany         => 'backend_busy ',
	backendConnFailures       => 'backend_fail',
	backendConnReuses         => 'backend_reuse',
	backendConnRecycled       => 'backend_recycle',
	backendConnUnused         => 'backend_toolate',
	totalSessions             => 's_sess ',
	totalRequests             => 's_req ',
	totalPipe                 => 's_pipe',
	totalPass                 => 's_pass',
	totalFetch                => 's_fetch',
	totalHeaderBytes          => 's_req_hdrbytes',
	totalBodyBytes            => 's_req_bodybytes'
	);

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

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

0;
@endperl@

@foreach $i scalar@
static int
handle_$i(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    uint32_t val;
    /* We are never called for a GETNEXT if it's registered as a
       "instance", as it's "magically" handled for us.  */

    /* an instance handler also only hands us one request at a time, so
       we don't need to loop over a list of requests; we'll only get one.
    */
  @startperl@
    &{$vars{'varnish_translate'}}($vars{'i'});
  @endperl@
    if (reqinfo->mode == MODE_GET) {
	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));
    } else {
      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(("$name", "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();
}

Return to:

Send suggestions and report system problems to the System administrator.