diff options
Diffstat (limited to 'src/varnish_mib.mib2c')
-rw-r--r-- | src/varnish_mib.mib2c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/src/varnish_mib.mib2c b/src/varnish_mib.mib2c index a5367e0..9d49ce9 100644 --- a/src/varnish_mib.mib2c +++ b/src/varnish_mib.mib2c @@ -1,8 +1,8 @@ # This file is part of varnish-mib -*- c -*- -# Copyright (C) 2014-2015 Sergey Poznyakoff +# Copyright (C) 2014-2016 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. # @@ -21,15 +21,13 @@ buffer-read-only: t End: vi: set ro: */ @enddefine@ @startperl@ -$vars{'varnish_translate'} = sub { - my $name = shift; - my %trans = ( +$vars{'varnish_translate_table'} = { uptime => [ 'MAIN', 'uptime' ], clientAcceptedConnections => [ 'MAIN', 'sess_conn' ], clientRequestsReceived => [ 'MAIN', 'client_req' ], clientCacheHits => [ 'MAIN', 'cache_hit' ], clientCacheHitsPass => [ 'MAIN', 'cache_hitpass' ], clientCacheMisses => [ 'MAIN', 'cache_miss' ], @@ -99,27 +97,37 @@ $vars{'varnish_translate'} = sub { bansLurkerObjKilled => [ 'MAIN', 'bans_lurker_obj_killed' ], bansDups => [ 'MAIN', 'bans_dups' ], bansLurkerContention => [ 'MAIN', 'bans_lurker_contention' ], bansPersistedBytes => [ 'MAIN', 'bans_persisted_bytes' ], bansPersistedFragmentation => [ 'MAIN', 'bans_persisted_fragmentation' ], - ); +}; + +$vars{'varnish_translate'} = sub { + my $name = shift; - my $r = $trans{$name}; + my $r = $vars{'varnish_translate_table'}->{$name}; if (!defined($r)) { print STDERR "no translation for $name!\n"; exit(1); } $vars{'varnish_type'} = $r->[0]; $vars{'varnish_member'} = $r->[1]; if ($#{$r} == 2) { @vars{keys %{$r->[2]}} = values %{$r->[2]}; } else { delete $vars{$setkw}; } + if ($vars{'varnish_type'} eq 'MAIN') { + $vars{'varnish_if'} = "#if HAVE_STRUCT_VSC_C_MAIN_" . uc($vars{'varnish_member'}); + $vars{'varnish_endif'} = '#endif'; + } else { + delete $vars{'varnish_if'}; + delete $vars{'varnish_endif'} + } return 0; }; %field_dim_tab = ( vbeIPv4 => 4, vbeIPv6 => 16 @@ -221,26 +229,26 @@ varnish_get_vsm_data() An instance handler only hands us one request at a time, unwrapping any eventual GETNEXT requests. */ @foreach $i scalar@ + @startperl@ + &{$vars{'varnish_translate'}}($vars{'i'}); + @endperl@ +$varnish_if 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 (!varnish_get_vsm_data()) return SNMP_ERR_NOSUCHNAME; switch(reqinfo->mode) { case MODE_GET: @if $varnish_type eq 'MAIN'@ @@ -356,12 +364,13 @@ handle_$i(netsnmp_mib_handler *handler, snmp_log(LOG_ERR, "unknown mode (%d) in handle_${i}\n", reqinfo->mode ); return SNMP_ERR_GENERR; } return SNMP_ERR_NOERROR; } +$varnish_endif @end@ @foreach $i table@ ## Determine the first/last column names @eval $first_column = "-"@ @eval $last_column = "-"@ @@ -540,13 +549,18 @@ initialize_table_$i(void) /** Initializes the $name module */ void init_$modulename(void) { @foreach $i scalar@ + @startperl@ + &{$vars{'varnish_translate'}}($vars{'i'}); + @endperl@ +$varnish_if const oid ${i}_oid[] = { $i.commaoid }; +$varnish_endif @end@ DEBUGMSGTL(("$modulename", "Initializing\n")); if (!register_config_handler("snmpd", "varnishBanTableTimeout", varnish_ban_table_timeout_parser, @@ -564,22 +578,27 @@ init_$modulename(void) varnish_vcli_timeout_parser, NULL, "varnishCLIPortTimeout SECONDS")) snmp_log(LOG_ERR,"can't register config handler\n"); @foreach $i scalar@ + @startperl@ + &{$vars{'varnish_translate'}}($vars{'i'}); + @endperl@ +$varnish_if 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@ )); +$varnish_endif @end@ @foreach $i table@ initialize_table_$i(); @end@ varnish_snmp_init(); } |