diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-26 07:34:42 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-26 07:59:50 +0200 |
commit | 50813ca9aa276c72e6f766a5ecd23c1170273528 (patch) | |
tree | 61a3246051156b10f14f35481368ba589b8b5b4f | |
parent | 2301256beda8480560c6e8053dc209989c8afeb8 (diff) | |
download | varnish-mib-50813ca9aa276c72e6f766a5ecd23c1170273528.tar.gz varnish-mib-50813ca9aa276c72e6f766a5ecd23c1170273528.tar.bz2 |
Implement table of bans
* src/varnish_mib.h: Removed; from now on it is generated
from varnish_mib.mib2c in pair with varnish_mib.c
* src/.gitignore: Add varnish_mib.h
* src/Makefile.am: Change rules accordingly.
* src/VARNISH-MIB.txt: Define table of bans.
* src/ban.c: Implement table of bans.
* src/varnish_mib.mib2c: Implement table support.
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/VARNISH-MIB.txt | 83 | ||||
-rw-r--r-- | src/ban.c | 191 | ||||
-rw-r--r-- | src/varnish_mib.h | 52 | ||||
-rw-r--r-- | src/varnish_mib.mib2c | 258 |
6 files changed, 503 insertions, 87 deletions
diff --git a/src/.gitignore b/src/.gitignore index 49f397c..61958b7 100644 --- a/src/.gitignore +++ b/src/.gitignore | |||
@@ -1 +1,2 @@ | |||
1 | varnish_mib.c | 1 | varnish_mib.c |
2 | varnish_mib.h | ||
diff --git a/src/Makefile.am b/src/Makefile.am index a0e7e72..4643fde 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -29,5 +29,6 @@ varnish_mib_la_SOURCES = \ | |||
29 | BUILT_SOURCES = \ | 29 | BUILT_SOURCES = \ |
30 | varnish_mib.c | 30 | varnish_mib.c\ |
31 | varnish_mib.h | ||
31 | 32 | ||
32 | varnish_mib.c: varnish_mib.mib2c VARNISH-MIB.txt | 33 | varnish_mib.c varnish_mib.h: varnish_mib.mib2c VARNISH-MIB.txt |
33 | 34 | ||
diff --git a/src/VARNISH-MIB.txt b/src/VARNISH-MIB.txt index cde935a..47e39c8 100644 --- a/src/VARNISH-MIB.txt +++ b/src/VARNISH-MIB.txt | |||
@@ -13,2 +13,4 @@ IMPORTS | |||
13 | FROM SNMPv2-SMI | 13 | FROM SNMPv2-SMI |
14 | DateAndTime | ||
15 | FROM SNMPv2-TC | ||
14 | OBJECT-GROUP, MODULE-COMPLIANCE | 16 | OBJECT-GROUP, MODULE-COMPLIANCE |
@@ -17,3 +19,3 @@ IMPORTS | |||
17 | varnishMIB MODULE-IDENTITY | 19 | varnishMIB MODULE-IDENTITY |
18 | LAST-UPDATED "201411241848Z" | 20 | LAST-UPDATED "201411260759Z" |
19 | ORGANIZATION "Shared Autonomous sYstems" | 21 | ORGANIZATION "Shared Autonomous sYstems" |
@@ -22,3 +24,3 @@ varnishMIB MODULE-IDENTITY | |||
22 | "This MIB module defines objects for Varnish reverse web proxy." | 24 | "This MIB module defines objects for Varnish reverse web proxy." |
23 | REVISION "201411241848Z" | 25 | REVISION "201411260759Z" |
24 | DESCRIPTION | 26 | DESCRIPTION |
@@ -76,4 +78,10 @@ clientCacheMisses OBJECT-TYPE | |||
76 | 78 | ||
79 | VarnishBanString ::= TEXTUAL-CONVENTION | ||
80 | DISPLAY-HINT "1024t" | ||
81 | STATUS current | ||
82 | DESCRIPTION "" | ||
83 | SYNTAX OCTET STRING (SIZE (0..1024)) | ||
84 | |||
77 | clientBan OBJECT-TYPE | 85 | clientBan OBJECT-TYPE |
78 | SYNTAX OCTET STRING (SIZE(0..1024)) | 86 | SYNTAX VarnishBanString |
79 | MAX-ACCESS read-write | 87 | MAX-ACCESS read-write |
@@ -529,4 +537,59 @@ bansPersistedFragmentation OBJECT-TYPE | |||
529 | ::= { bans 17 } | 537 | ::= { bans 17 } |
530 | |||
531 | 538 | ||
539 | banTable OBJECT-TYPE | ||
540 | SYNTAX SEQUENCE OF VarnishBanEntry | ||
541 | MAX-ACCESS not-accessible | ||
542 | STATUS current | ||
543 | DESCRIPTION | ||
544 | "The (conceptual) table listing available bans" | ||
545 | ::= { bans 18 } | ||
546 | |||
547 | varnishBanEntry OBJECT-TYPE | ||
548 | SYNTAX VarnishBanEntry | ||
549 | MAX-ACCESS not-accessible | ||
550 | STATUS current | ||
551 | DESCRIPTION | ||
552 | "An entry (conceptual row) representing a ban" | ||
553 | INDEX { banIndex } | ||
554 | ::= { banTable 1 } | ||
555 | |||
556 | VarnishBanEntry ::= SEQUENCE { | ||
557 | banIndex Integer32, | ||
558 | banTime DateAndTime, | ||
559 | banRefCount Counter64, | ||
560 | banExpression VarnishBanString | ||
561 | } | ||
562 | |||
563 | banIndex OBJECT-TYPE | ||
564 | SYNTAX Integer32 | ||
565 | MAX-ACCESS not-accessible | ||
566 | STATUS current | ||
567 | DESCRIPTION | ||
568 | "A number uniquely identifying each ban" | ||
569 | ::= { varnishBanEntry 1 } | ||
570 | |||
571 | banTime OBJECT-TYPE | ||
572 | SYNTAX DateAndTime | ||
573 | MAX-ACCESS read-only | ||
574 | STATUS current | ||
575 | DESCRIPTION | ||
576 | "Time when the ban was created" | ||
577 | ::= { varnishBanEntry 2 } | ||
578 | |||
579 | banRefCount OBJECT-TYPE | ||
580 | SYNTAX Counter32 | ||
581 | MAX-ACCESS read-only | ||
582 | STATUS current | ||
583 | DESCRIPTION | ||
584 | "Number of references to this ban" | ||
585 | ::= { varnishBanEntry 3 } | ||
586 | |||
587 | banExpression OBJECT-TYPE | ||
588 | SYNTAX VarnishBanString | ||
589 | MAX-ACCESS read-only | ||
590 | STATUS current | ||
591 | DESCRIPTION | ||
592 | "VCL expression of the ban" | ||
593 | ::= { varnishBanEntry 4 } | ||
594 | |||
532 | -- | 595 | -- |
@@ -587,4 +650,9 @@ varnishGroup OBJECT-GROUP | |||
587 | threadsFailed, | 650 | threadsFailed, |
588 | threadsQueueLength | 651 | threadsQueueLength, |
589 | 652 | banTable, | |
653 | varnishBanEntry, | ||
654 | banIndex, | ||
655 | banTime, | ||
656 | banRefCount, | ||
657 | banExpression | ||
590 | } | 658 | } |
@@ -604,4 +672,3 @@ varnishStandardComplianceV1 MODULE-COMPLIANCE | |||
604 | MODULE | 672 | MODULE |
605 | MANDATORY-GROUPS { | 673 | MANDATORY-GROUPS { varnishGroup } |
606 | varnishGroup} | ||
607 | 674 | ||
@@ -18,2 +18,3 @@ | |||
18 | #include "varnish_mib.h" | 18 | #include "varnish_mib.h" |
19 | #include <ctype.h> | ||
19 | 20 | ||
@@ -52,3 +53,3 @@ varnish_ban(netsnmp_agent_request_info *reqinfo, | |||
52 | expr[len] = 0; | 53 | expr[len] = 0; |
53 | DEBUGMSGTL(("vcli_mib", "ban %s\n", expr)); | 54 | DEBUGMSGTL(("varnish_ban", "setting ban %s\n", expr)); |
54 | rc = vcli_connect(vd, &conn); | 55 | rc = vcli_connect(vd, &conn); |
@@ -56,3 +57,3 @@ varnish_ban(netsnmp_agent_request_info *reqinfo, | |||
56 | rc = send_ban_cmd(&conn, expr); | 57 | rc = send_ban_cmd(&conn, expr); |
57 | vcli_disconnect(&conn); | 58 | vcli_disconnect(&conn); |
58 | } | 59 | } |
@@ -61,2 +62,188 @@ varnish_ban(netsnmp_agent_request_info *reqinfo, | |||
61 | } | 62 | } |
63 | |||
64 | unsigned banTable_timeout = 60; | ||
62 | 65 | ||
66 | /* | ||
67 | * create a new row in the table | ||
68 | */ | ||
69 | static struct banTable_entry * | ||
70 | create_entry(netsnmp_tdata *table_data, long idx, struct banTable_entry *ent) | ||
71 | { | ||
72 | struct banTable_entry *entry; | ||
73 | netsnmp_tdata_row *row; | ||
74 | |||
75 | entry = SNMP_MALLOC_TYPEDEF(struct banTable_entry); | ||
76 | if (!entry) | ||
77 | return NULL; | ||
78 | |||
79 | row = netsnmp_tdata_create_row(); | ||
80 | if (!row) { | ||
81 | SNMP_FREE(entry); | ||
82 | return NULL; | ||
83 | } | ||
84 | row->data = entry; | ||
85 | *entry = *ent; | ||
86 | |||
87 | entry->banIndex = idx; | ||
88 | netsnmp_tdata_row_add_index(row, ASN_INTEGER, | ||
89 | &entry->banIndex, | ||
90 | sizeof(entry->banIndex)); | ||
91 | if (table_data) | ||
92 | netsnmp_tdata_add_row(table_data, row); | ||
93 | return entry; | ||
94 | } | ||
95 | |||
96 | #define TMSEC(t) (((t)->tm_hour * 60 + (t)->tm_min) * 60 + (t)->tm_sec) | ||
97 | |||
98 | static int | ||
99 | utc_offset (void) | ||
100 | { | ||
101 | time_t t = time (NULL); | ||
102 | struct tm ltm = *localtime (&t); | ||
103 | struct tm gtm = *gmtime (&t); | ||
104 | int d = TMSEC (<m) - TMSEC (>m); | ||
105 | if (!(ltm.tm_year = gtm.tm_year && ltm.tm_mon == gtm.tm_mon)) | ||
106 | d += 86400; | ||
107 | return d / 60; | ||
108 | } | ||
109 | |||
110 | /* Refill the ban table */ | ||
111 | int | ||
112 | banTable_load(netsnmp_cache *cache, void *vmagic) | ||
113 | { | ||
114 | netsnmp_tdata *table = (netsnmp_tdata *) vmagic; | ||
115 | long idx = 0; | ||
116 | int rc; | ||
117 | struct vcli_conn conn; | ||
118 | char *p; | ||
119 | struct VSM_data *vd; | ||
120 | |||
121 | DEBUGMSGTL(("varnish_ban", "reloading ban table")); | ||
122 | vd = varnish_get_vsm_data(); | ||
123 | rc = vcli_connect(vd, &conn); | ||
124 | if (rc != SNMP_ERR_NOERROR) | ||
125 | return rc; | ||
126 | |||
127 | if (vcli_asprintf(&conn, "ban.list\n") || vcli_write(&conn)) | ||
128 | return SNMP_ERR_GENERR; | ||
129 | |||
130 | if (vcli_read_response(&conn)) | ||
131 | return SNMP_ERR_GENERR; | ||
132 | |||
133 | if (conn.resp != CLIS_OK) { | ||
134 | snmp_log(LOG_ERR, "ban.list command rejected: %u %s\n", | ||
135 | conn.resp, conn.base); | ||
136 | return SNMP_ERR_GENERR; | ||
137 | } | ||
138 | |||
139 | p = conn.base; | ||
140 | while (p < conn.base + conn.bufsize) { | ||
141 | char *q; | ||
142 | struct banTable_entry e; | ||
143 | struct tm *tm; | ||
144 | time_t t; | ||
145 | int n; | ||
146 | |||
147 | if (*p == '\n') { | ||