aboutsummaryrefslogtreecommitdiff
path: root/src/mysqlstat_mib.mib2c
blob: 8f9663d44ae5f81fbb211eea9675367fadd22274 (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
249
250
251
252
253
254
255
256
257
# This file is part of Mysqlstat -*- autoconf -*-
# Copyright (C) 2014-2016 Sergey Poznyakoff
#
# Mysqlstat 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.
#
# Mysqlstat 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 Mysqlstat.  If not, see <http://www.gnu.org/licenses/>.

@define ROCOM@
/* Local variables:
   buffer-read-only: t
   End:
   vi: set ro:
*/
@enddefine@
@startperl@
$vars{'mysqlstat_translate_table'} = {
	replSlaveIOState        => [
		'MYSQLSTAT_CACHE_REPL', 'Slave_IO_State' ],
	replMasterLogFile       => [
		'MYSQLSTAT_CACHE_REPL',  'Master_Log_File' ],
	replReadMasterLogPos    => [
		'MYSQLSTAT_CACHE_REPL',  'Read_Master_Log_Pos' ],
	replRelayLogFile        => [
		'MYSQLSTAT_CACHE_REPL', 'Relay_Log_File' ],
	replRelayLogPos         => [
		'MYSQLSTAT_CACHE_REPL', 'Relay_Log_Pos' ],
	replRelayMasterLogFile  => [
		'MYSQLSTAT_CACHE_REPL', 'Relay_Master_Log_File' ],
	replSlaveIORunning      => [
		'MYSQLSTAT_CACHE_REPL', 'Slave_IO_Running' ],
	replSlaveSQLRunning     => [
		'MYSQLSTAT_CACHE_REPL', 'Slave_SQL_Running' ],
	replLastSQLErrno        => [
		'MYSQLSTAT_CACHE_REPL', 'Last_SQL_Errno' ],
	replLastSQLError        => [
		'MYSQLSTAT_CACHE_REPL', 'Last_SQL_Error' ],
	replLastIOErrno         => [
		'MYSQLSTAT_CACHE_REPL', 'Last_IO_Errno' ],
	replLastIOError         => [
		'MYSQLSTAT_CACHE_REPL', 'Last_IO_Error' ],
	replExecMasterLogPos    => [
		'MYSQLSTAT_CACHE_REPL', 'Exec_Master_Log_Pos' ],
	replRelayLogSpace       => [
		'MYSQLSTAT_CACHE_REPL', 'Relay_Log_Space' ],
	replSecondsBehindMaster => [
		'MYSQLSTAT_CACHE_REPL', 'Seconds_Behind_Master' ]
};

$vars{'mysqlstat_translate'} = sub {
    my ($name) = @_;
    my $r = $vars{'mysqlstat_translate_table'}->{$name};
    if (!defined($r)) {
	print STDERR "no translation for $name!\n";
	exit(1);
    }

    $vars{'mysqlstat_id'}   = $r->[0];
    $vars{'mysqlstat_name'} = $r->[1];
#    $vars{'mysqlstat_type'} = $r->[2];
    return 0;
};	
	
$vars{'modulename'} = $vars{'name'};
$vars{'modulename'} =~ s#.*/##;
$vars{'modulename'} =~ s/\.c$//;
#print "$vars{'modulename'}\n";

0;
@endperl@
@open ${name}@
/* THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT. */

#include "mysqlstat.h"

/* Variable handlers.

   An instance handler only hands us one request at a time, unwrapping
   any eventual GETNEXT requests.  
*/

@foreach $i scalar@
  @startperl@
    &{$vars{'mysqlstat_translate'}}($vars{'i'});
  @endperl@

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@
    char const *val = mysqlstat_get($mysqlstat_id, "$mysqlstat_name");

    if (!val)
	    return SNMP_ERR_NOSUCHNAME;
  
    switch(reqinfo->mode) {
    case MODE_GET:
  @if $i.type eq 'ASN_COUNTER64'@
    {
        struct counter64 ctr;
 	uint64_t n = strtoull(val, NULL, 10);
	ctr.high = n >> 32;
	ctr.low = n & 0xffffffff;
	snmp_set_var_typed_value(requests->requestvb, $i.type,
				 &ctr,
				 sizeof(ctr));
    }				 
  @elsif $i.type eq 'ASN_OCTET_STR'@
    snmp_set_var_typed_value(requests->requestvb, $i.type,
	                     val, strlen(val));
    break;
  @elsif $i.type eq 'ASN_COUNTER'@
    {
	uint32_t n = strtoul(val, NULL, 10);
	snmp_set_var_typed_value(requests->requestvb, $i.type,
				 &n,
				 sizeof(n));
    }
  @elsif $i.type eq 'ASN_INTEGER'@
    {
	uint32_t n = strtoul(val, NULL, 10);
	snmp_set_var_typed_value(requests->requestvb, $i.type,
				 &n,
				 sizeof(n));
    }
  @elsif $i.type eq 'ASN_TIMETICKS'@
    {
	uint32_t n = strtoul(val, NULL, 10);
	snmp_set_var_typed_value(requests->requestvb, $i.type,
				 &n,
				 sizeof(n));
    }
  @else@
    @printf "unrecognized type %s for %s" $i.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 $mysqlstat_set_reserve2 ne ''@
        if ($mysqlstat_set_reserve2 (reqinfo, requests, vd)) {
	    netsnmp_set_request_error(reqinfo, requests,
				      SNMP_ERR_RESOURCEUNAVAILABLE);
	}
    @end@
	break;

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

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

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

    case MODE_SET_UNDO:
    @if $mysqlstat_set_undo ne ''@
	# UNDO and return to previous value for the object
        if ($mysqlstat_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@
    @startperl@
      &{$vars{'mysqlstat_translate'}}($vars{'i'});
    @endperl@
$mysqlstat_if
    const oid ${i}_oid[] = { $i.commaoid };
$mysqlstat_endif
  @end@

  DEBUGMSGTL(("$modulename", "Initializing\n"));
  
  @foreach $i scalar@
    @startperl@
      &{$vars{'mysqlstat_translate'}}($vars{'i'});
    @endperl@
    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@
}

void
deinit_$modulename(void)
{
	/* Nothing */
}
@calldefine ROCOM@


Return to:

Send suggestions and report system problems to the System administrator.