summaryrefslogtreecommitdiffabout
path: root/src/varnish_mib.mib2c
blob: 798fc53f6835895f9d7caa2f1c9476572051a842 (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
# 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 <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@

/* 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)
{
    uint32_t val;
    
  @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();
}
@calldefine ROCOM@

Return to:

Send suggestions and report system problems to the System administrator.