diff options
Diffstat (limited to 'src/varnish_mib.mib2c')
-rw-r--r-- | src/varnish_mib.mib2c | 101 |
1 files changed, 93 insertions, 8 deletions
diff --git a/src/varnish_mib.mib2c b/src/varnish_mib.mib2c index 7084476..2b12090 100644 --- a/src/varnish_mib.mib2c +++ b/src/varnish_mib.mib2c @@ -24,6 +24,8 @@ */ @enddefine@ @startperl@ +use VarnishMib::MIBTable; + $vars{'varnish_translate_table'} = { uptime => [ DICT => 'MAIN.uptime' ], clientAcceptedConnections => [ DICT => 'MAIN.sess_conn' ], @@ -96,7 +98,7 @@ $vars{'varnish_translate_table'} = { bansLurkerObjKilled => [ DICT => 'MAIN.bans_lurker_obj_killed' ], bansDups => [ DICT => 'MAIN.bans_dups' ], bansLurkerContention => [ DICT => 'MAIN.bans_lurker_contention' ], - bansPersistedBytes => [ DICT => 'MAIN.bans_persisted_bytes' ], + bansPersistedBytes => [ DICT => 'MAIN.bans_persisted_bytes' ], bansPersistedFragmentation => [ DICT => 'MAIN.bans_persisted_fragmentation' ], objectsCount => [ DICT => 'MAIN.n_object' ], @@ -117,6 +119,12 @@ $vars{'varnish_translate_table'} = { vclFail => [ DICT => 'MAIN.vcl_fail' ], }; +$vars{'varnish_hash_table'} = new VarnishMib::MIBTable( + 'struct VSC_point *', + $vars{'varnish_translate_table'}, + prefix => 'vmib_', max_collisions => 0 + ); + my @reset_names; $vars{'varnish_translate'} = sub { @@ -155,12 +163,11 @@ $vars{'set_field_dim'} = sub { $vars{'modulename'} = $vars{'name'}; $vars{'modulename'} =~ s#.*/##; $vars{'modulename'} =~ s/\.c$//; -#print "$vars{'modulename'}\n"; - 0; @endperl@ @open ${modulename}.h@ /* THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT. */ + #include <config.h> #include <stddef.h> #include <stdlib.h> @@ -189,10 +196,6 @@ int varnish_ban(netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests, struct vsm *vsm); -int dict_lookup(char const *key, uint64_t *val); -void dict_install(struct VSC_point const *pt); -void dict_load(struct vsc *vsc); - @open ${name}@ /* THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT. */ @@ -202,6 +205,8 @@ void dict_load(struct vsc *vsc); static struct vsm *vd; static struct vsc *vsc; +static void dict_load(struct vsc *vsc); + int post_config(int majorID, int minorID, void *serverarg, void *clientarg) { @@ -253,6 +258,80 @@ varnish_get_vsm_data(void) return vd; } +${varnish_hash_table} + +static struct VSC_point ** +varnish_var_lookup(char const *str) +{ + if (str) { + int i, h; + + h = string_hash(str, vmib_hash_table_size); + i = h; + while (vmib_hash_table[i] != -1) { + if (strcmp(vmib_name_table[vmib_hash_table[i]], str) == 0) + return &vmib_data_table[vmib_hash_table[i]]; + i = (i + 1) % vmib_hash_table_size; + if (i == h) + break; + } + } + return NULL; +} + +static inline struct VSC_point * +varnish_get_oid(int i) +{ + return vmib_data_table[i]; +} + +static void +dict_clear(void) +{ + int i; + for (i = 0; i < MAX_VMIB_OID; i++) + if (vmib_data_table[i]) + VSC_Destroy_Point(&vmib_data_table[i]); +} + +static struct VSC_point const * +dict_install(struct VSC_point const *pt) +{ + struct VSC_point **ent; + + ent = varnish_var_lookup(pt->name); + if (!ent) + return NULL; + if (*ent) + VSC_Destroy_Point(ent); + *ent = VSC_Clone_Point(pt); + return *ent; +} + +static int +load_cb(void *priv, const struct VSC_point *vpt) +{ + AZ(strcmp(vpt->ctype, "uint64_t")); + if (strncmp(vpt->name, "VBE.", 4) == 0) { + char const *name = vpt->name + 4; + char *p = strrchr(name, '.'); + if (p) { + backend_register(name, p - name, p + 1, vpt); + } + } + vpt = dict_install(vpt); + return 0; +} + +static void +dict_load(struct vsc *vsc) +{ + struct vsm_fantom fantom = VSM_FANTOM_NULL; + dict_clear(); + backend_clear(); + VSC_Iter(vsc, &fantom, load_cb, NULL); +} + /* Variable handlers. An instance handler only hands us one request at a time, unwrapping @@ -282,9 +361,12 @@ handle_$i(netsnmp_mib_handler *handler, case MODE_GET: @if $varnish_type eq 'DICT'@ { + struct VSC_point *ent = varnish_get_oid($i); uint64_t val; - if (dict_lookup("$varnish_member", &val)) + + if (!ent) return SNMP_ERR_NOSUCHNAME; + val = *(uint64_t*)ent->ptr; @if $i.type eq 'ASN_COUNTER64'@ { struct counter64 ctr; @@ -295,6 +377,9 @@ handle_$i(netsnmp_mib_handler *handler, sizeof(ctr)); } @else@ + @if $i.type eq 'ASN_TIMETICKS'@ + val *= 100; + @end@ snmp_set_var_typed_value(requests->requestvb, $i.type, &val, sizeof(val)); |