diff options
Diffstat (limited to '')
27 files changed, 7561 insertions, 0 deletions
diff --git a/admin/dyncookie/dyncookie.c b/admin/dyncookie/dyncookie.c new file mode 100644 index 0000000..ddb71a7 --- /dev/null +++ b/admin/dyncookie/dyncookie.c @@ -0,0 +1,56 @@ +/* + * Dynamic server cookie calculator + * + * Copyright 2021 Willy Tarreau <w@1wt.eu> + * + * This program 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 + * 2 of the License, or (at your option) any later version. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <arpa/inet.h> + +#include <haproxy/xxhash.h> + +__attribute__((noreturn)) void die(int code, const char *format, ...) +{ + va_list args; + + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + exit(code); +} + +int main(int argc, char **argv) +{ + size_t key_len; + int addr_len; + char *buf; + int port; + + if (argc < 4) + die(1, "Usage: %s <key> <ip> <port>\n", argv[0]); + + key_len = strlen(argv[1]); + buf = realloc(strdup(argv[1]), key_len + 16 + 4); + if (!buf) + die(2, "Not enough memory\n"); + + if (inet_pton(AF_INET, argv[2], buf + key_len) > 0) + addr_len = 4; + else if (inet_pton(AF_INET6, argv[2], buf + key_len) > 0) + addr_len = 16; + else + die(3, "Cannot parse address <%s> as IPv4/IPv6\n", argv[2]); + + port = htonl(atoi(argv[3])); + memcpy(buf + key_len + addr_len, &port, 4); + printf("%016llx\n", (long long)XXH64(buf, key_len + addr_len + 4, 0)); + return 0; +} diff --git a/admin/halog/README b/admin/halog/README new file mode 100644 index 0000000..ff1bb12 --- /dev/null +++ b/admin/halog/README @@ -0,0 +1,4 @@ +This needs to be built from the top makefile, for example : + + make admin/halog/halog + diff --git a/admin/halog/fgets2.c b/admin/halog/fgets2.c new file mode 100644 index 0000000..7fbe16b --- /dev/null +++ b/admin/halog/fgets2.c @@ -0,0 +1,267 @@ +/* + * fast fgets() replacement for log parsing + * + * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, version 2.1 + * exclusively. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * This function manages its own buffer and returns a pointer to that buffer + * in order to avoid expensive memory copies. It also checks for line breaks + * 32 or 64 bits at a time. It could be improved a lot using mmap() but we + * would not be allowed to replace trailing \n with zeroes and we would be + * limited to small log files on 32-bit machines. + * + */ + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <unistd.h> + +#ifndef FGETS2_BUFSIZE +#define FGETS2_BUFSIZE (256*1024) +#endif + +/* memchr() is faster in glibc with SSE since commit 093ecf92998de2 */ +#if defined(__x86_64__) && defined(__GLIBC__) && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 15)) +#define USE_MEMCHR +#endif + +/* return non-zero if the integer contains at least one zero byte */ +static inline __attribute__((unused)) unsigned int has_zero32(unsigned int x) +{ + unsigned int y; + + /* Principle: we want to perform 4 tests on one 32-bit int at once. For + * this, we have to simulate an SIMD instruction which we don't have by + * default. The principle is that a zero byte is the only one which + * will cause a 1 to appear on the upper bit of a byte/word/etc... when + * we subtract 1. So we can detect a zero byte if a one appears at any + * of the bits 7, 15, 23 or 31 where it was not. It takes only one + * instruction to test for the presence of any of these bits, but it is + * still complex to check for their initial absence. Thus, we'll + * proceed differently : we first save and clear only those bits, then + * we check in the final result if one of them is present and was not. + * The order of operations below is important to save registers and + * tests. The result is used as a boolean, so the last test must apply + * on the constant so that it can efficiently be inlined. + */ +#if defined(__i386__) + /* gcc on x86 loves copying registers over and over even on code that + * simple, so let's do it by hand to prevent it from doing so :-( + */ + asm("lea -0x01010101(%0),%1\n" + "not %0\n" + "and %1,%0\n" + : "=a" (x), "=r"(y) + : "0" (x) + ); + return x & 0x80808080; +#else + y = x - 0x01010101; /* generate a carry */ + x = ~x & y; /* clear the bits that were already set */ + return x & 0x80808080; +#endif +} + +/* return non-zero if the argument contains at least one zero byte. See principle above. */ +static inline __attribute__((unused)) unsigned long long has_zero64(unsigned long long x) +{ + unsigned long long y; + + y = x - 0x0101010101010101ULL; /* generate a carry */ + y &= ~x; /* clear the bits that were already set */ + return y & 0x8080808080808080ULL; +} + +static inline __attribute__((unused)) unsigned long has_zero(unsigned long x) +{ + return (sizeof(x) == 8) ? has_zero64(x) : has_zero32(x); +} + +/* find a '\n' between <next> and <end>. Warning: may read slightly past <end>. + * If no '\n' is found, <end> is returned. + */ +static char *find_lf(char *next, char *end) +{ +#if defined USE_MEMCHR + /* some recent libc use platform-specific optimizations to provide more + * efficient byte search than below (eg: glibc 2.11 on x86_64). + */ + next = memchr(next, '\n', end - next); + if (!next) + next = end; +#else + if (sizeof(long) == 4) { /* 32-bit system */ + /* this is a speed-up, we read 32 bits at once and check for an + * LF character there. We stop if found then continue one at a + * time. + */ + while (next < end && (((unsigned long)next) & 3) && *next != '\n') + next++; + + /* Now next is multiple of 4 or equal to end. We know we can safely + * read up to 32 bytes past end if needed because they're allocated. + */ + while (next < end) { + if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A)) + break; + next += 4; + if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A)) + break; + next += 4; + if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A)) + break; + next += 4; + if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A)) + break; + next += 4; + if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A)) + break; + next += 4; + if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A)) + break; + next += 4; + if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A)) + break; + next += 4; + if (has_zero32(*(unsigned int *)next ^ 0x0A0A0A0A)) + break; + next += 4; + } + } + else { /* 64-bit system */ + /* this is a speed-up, we read 64 bits at once and check for an + * LF character there. We stop if found then continue one at a + * time. + */ + if (next <= end) { + /* max 3 bytes tested here */ + while ((((unsigned long)next) & 3) && *next != '\n') + next++; + + /* maybe we have can skip 4 more bytes */ + if ((((unsigned long)next) & 4) && !has_zero32(*(unsigned int *)next ^ 0x0A0A0A0AU)) + next += 4; + } + + /* now next is multiple of 8 or equal to end */ + while (next <= (end-68)) { + if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL)) + break; + next += 8; + if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL)) + break; + next += 8; + if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL)) + break; + next += 8; + if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL)) + break; + next += 8; + if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL)) + break; + next += 8; + if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL)) + break; + next += 8; + if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL)) + break; + next += 8; + if (has_zero64(*(unsigned long long *)next ^ 0x0A0A0A0A0A0A0A0AULL)) + break; + next += 8; + } + + /* maybe we can skip 4 more bytes */ + if (!has_zero32(*(unsigned int *)next ^ 0x0A0A0A0AU)) + next += 4; + } + + /* We finish if needed : if <next> is below <end>, it means we + * found an LF in one of the 4 following bytes. + */ + while (next < end) { + if (*next == '\n') + break; + next++; + } +#endif + return next; +} + +const char *fgets2(FILE *stream) +{ + static char buffer[FGETS2_BUFSIZE + 68]; /* Note: +32 is enough on 32-bit systems */ + static char *end = buffer; + static char *line = buffer; + char *next; + int ret; + + next = line; + + while (1) { + next = find_lf(next, end); + if (next < end) { + const char *start = line; + *next = '\0'; + line = next + 1; + return start; + } + + /* we found an incomplete line. First, let's move the + * remaining part of the buffer to the beginning, then + * try to complete the buffer with a new read. We can't + * rely on <next> anymore because it went past <end>. + */ + if (line > buffer) { + if (end != line) + memmove(buffer, line, end - line); + end = buffer + (end - line); + next = end; + line = buffer; + } else { + if (end == buffer + FGETS2_BUFSIZE) + return NULL; + } + + ret = read(fileno(stream), end, buffer + FGETS2_BUFSIZE - end); + + if (ret <= 0) { + if (end == line) + return NULL; + + *end = '\0'; + end = line; /* ensure we stop next time */ + return line; + } + + end += ret; + *end = '\n'; /* make parser stop ASAP */ + /* search for '\n' again */ + } +} + +#ifdef BENCHMARK +int main() { + const char *p; + unsigned int lines = 0; + + while ((p=fgets2(stdin))) + lines++; + printf("lines=%u\n", lines); + return 0; +} +#endif diff --git a/admin/halog/halog.c b/admin/halog/halog.c new file mode 100644 index 0000000..45eec75 --- /dev/null +++ b/admin/halog/halog.c @@ -0,0 +1,1910 @@ +/* + * haproxy log statistics reporter + * + * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> + * + * This program 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 + * 2 of the License, or (at your option) any later version. + * + */ + +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <syslog.h> +#include <string.h> +#include <unistd.h> +#include <ctype.h> +#include <time.h> + +#include <haproxy/compiler.h> + +#include <import/eb32tree.h> +#include <import/eb64tree.h> +#include <import/ebistree.h> +#include <import/ebsttree.h> + +#define SOURCE_FIELD 5 +#define ACCEPT_FIELD 6 +#define SERVER_FIELD 8 +#define TIME_FIELD 9 +#define STATUS_FIELD 10 +#define BYTES_SENT_FIELD 11 +#define TERM_CODES_FIELD 14 +#define CONN_FIELD 15 +#define QUEUE_LEN_FIELD 16 +#define METH_FIELD 17 +#define URL_FIELD 18 +#define MAXLINE 16384 +#define QBITS 4 + +#define SEP(c) ((unsigned char)(c) <= ' ') +#define SKIP_CHAR(p,c) do { while (1) { int __c = (unsigned char)*p++; if (__c == c) break; if (__c <= ' ') { p--; break; } } } while (0) + +/* [0] = err/date, [1] = req, [2] = conn, [3] = resp, [4] = data */ +static struct eb_root timers[5] = { + EB_ROOT_UNIQUE, EB_ROOT_UNIQUE, EB_ROOT_UNIQUE, + EB_ROOT_UNIQUE, EB_ROOT_UNIQUE, +}; + +struct timer { + struct eb32_node node; + unsigned int count; +}; + +struct srv_st { + unsigned int st_cnt[6]; /* 0xx to 5xx */ + unsigned int nb_ct, nb_rt, nb_ok; + unsigned long long cum_ct, cum_rt; + struct ebmb_node node; + /* don't put anything else here, the server name will be there */ +}; + +struct url_stat { + union { + struct ebpt_node url; + struct eb64_node val; + } node; + char *url; + unsigned long long total_time; /* sum(all reqs' times) */ + unsigned long long total_time_ok; /* sum(all OK reqs' times) */ + unsigned long long total_bytes_sent; /* sum(all bytes sent) */ + unsigned int nb_err, nb_req; +}; + +#define FILT_COUNT_ONLY 0x01 +#define FILT_INVERT 0x02 +#define FILT_QUIET 0x04 +#define FILT_ERRORS_ONLY 0x08 +#define FILT_ACC_DELAY 0x10 +#define FILT_ACC_COUNT 0x20 +#define FILT_GRAPH_TIMERS 0x40 +#define FILT_PERCENTILE 0x80 +#define FILT_TIME_RESP 0x100 + +#define FILT_INVERT_ERRORS 0x200 +#define FILT_INVERT_TIME_RESP 0x400 + +#define FILT_COUNT_STATUS 0x800 +#define FILT_COUNT_SRV_STATUS 0x1000 +#define FILT_COUNT_TERM_CODES 0x2000 + +#define FILT_COUNT_URL_ONLY 0x004000 +#define FILT_COUNT_URL_COUNT 0x008000 +#define FILT_COUNT_URL_ERR 0x010000 +#define FILT_COUNT_URL_TTOT 0x020000 +#define FILT_COUNT_URL_TAVG 0x040000 +#define FILT_COUNT_URL_TTOTO 0x080000 +#define FILT_COUNT_URL_TAVGO 0x100000 + +#define FILT_HTTP_ONLY 0x200000 +#define FILT_TERM_CODE_NAME 0x400000 +#define FILT_INVERT_TERM_CODE_NAME 0x800000 + +#define FILT_HTTP_STATUS 0x1000000 +#define FILT_INVERT_HTTP_STATUS 0x2000000 +#define FILT_QUEUE_ONLY 0x4000000 +#define FILT_QUEUE_SRV_ONLY 0x8000000 + +#define FILT_COUNT_URL_BAVG 0x10000000 +#define FILT_COUNT_URL_BTOT 0x20000000 + +#define FILT_COUNT_URL_ANY (FILT_COUNT_URL_ONLY|FILT_COUNT_URL_COUNT|FILT_COUNT_URL_ERR| \ + FILT_COUNT_URL_TTOT|FILT_COUNT_URL_TAVG|FILT_COUNT_URL_TTOTO|FILT_COUNT_URL_TAVGO| \ + FILT_COUNT_URL_BAVG|FILT_COUNT_URL_BTOT) + +#define FILT_COUNT_COOK_CODES 0x40000000 +#define FILT_COUNT_IP_COUNT 0x80000000 + +#define FILT2_TIMESTAMP 0x01 +#define FILT2_PRESERVE_QUERY 0x02 +#define FILT2_EXTRACT_CAPTURE 0x04 + +unsigned int filter = 0; +unsigned int filter2 = 0; +unsigned int filter_invert = 0; +const char *line; +int linenum = 0; +int parse_err = 0; +int lines_out = 0; +int lines_max = -1; + +const char *fgets2(FILE *stream); + +void filter_count_url(const char *accept_field, const char *time_field, struct timer **tptr); +void filter_count_ip(const char *source_field, const char *accept_field, const char *time_field, struct timer **tptr); +void filter_count_srv_status(const char *accept_field, const char *time_field, struct timer **tptr); +void filter_count_cook_codes(const char *accept_field, const char *time_field, struct timer **tptr); +void filter_count_term_codes(const char *accept_field, const char *time_field, struct timer **tptr); +void filter_count_status(const char *accept_field, const char *time_field, struct timer **tptr); +void filter_graphs(const char *accept_field, const char *time_field, struct timer **tptr); +void filter_output_line(const char *accept_field, const char *time_field, struct timer **tptr); +void filter_extract_capture(const char *accept_field, const char *time_field, unsigned int, unsigned int); +void filter_accept_holes(const char *accept_field, const char *time_field, struct timer **tptr); + +void usage(FILE *output, const char *msg) +{ + fprintf(output, + "%s" + "Usage:\n" + " halog [-h|--help] for long help\n" + " halog [input_filters]* [modifiers]* [output_format] < log\n" + " inp = [-e|-E] [-H] [-Q|-QS] [-rt|-RT <time>] [-ad <delay>] [-ac <count>]\n" + " [-hs|-HS [min][:[max]]] [-tcn|-TCN <termcode>] [-time [min][:[max]]]\n" + " mod = [-q] [-v] [-m <lines>] [-s <skipflds>] [-query]\n" + " out = {-c|-u|-uc|-ue|-ua|-ut|-uao|-uto|-uba|-ubt|-hdr <block>:<field>|\n" + " -cc|-gt|-pct|-st|-tc|-srv|-ic}\n" + "\n", + msg ? msg : "" + ); +} + +void die(const char *msg) +{ + usage(stderr, msg); + exit(1); +} + +void help() +{ + usage(stdout, NULL); + printf( + "Input filters - several filters may be combined\n" + " -H only match lines containing HTTP logs (ignore TCP)\n" + " -E only match lines without any error (no 5xx status)\n" + " -e only match lines with errors (status 5xx or negative)\n" + " -rt|-RT <time> only match response times larger|smaller than <time>\n" + " -Q|-QS only match queued requests (any queue|server queue)\n" + " -tcn|-TCN <code> only match requests with/without termination code <code>\n" + " -hs|-HS <[min][:][max]> only match requests with HTTP status codes within/not\n" + " within min..max. Any of them may be omitted. Exact\n" + " code is checked for if no ':' is specified.\n" + " -time <[min][:max]> only match requests recorded between timestamps.\n" + " Any of them may be omitted.\n" + "Modifiers\n" + " -v invert the input filtering condition\n" + " -q don't report errors/warnings\n" + " -m <lines> limit output to the first <lines> lines\n" + " -s <skip_n_fields> skip n fields from the beginning of a line (default %d)\n" + " you can also use -n to start from earlier then field %d\n" + " -query preserve the query string for per-URL (-u*) statistics\n" + "\n" + "Output format - only one may be used at a time\n" + " -c only report the number of lines that would have been printed\n" + " -pct output connect and response times percentiles\n" + " -st output number of requests per HTTP status code\n" + " -cc output number of requests per cookie code (2 chars)\n" + " -tc output number of requests per termination code (2 chars)\n" + " -srv output statistics per server (time, requests, errors)\n" + " -ic output statistics per ip count (time, requests, errors)\n" + " -u* output statistics per URL (time, requests, errors)\n" + " Additional characters indicate the output sorting key :\n" + " -u : by URL, -uc : request count, -ue : error count\n" + " -ua : average response time, -ut : average total time\n" + " -uao, -uto: average times computed on valid ('OK') requests\n" + " -uba, -ubt: average bytes returned, total bytes returned\n" + " -hdr output captured header at the given <block>:<field>\n", + (int)SOURCE_FIELD, (int)SOURCE_FIELD + ); + exit(0); +} + + +/* return pointer to first char not part of current field starting at <p>. */ + +#if defined(__i386__) +/* this one is always faster on 32-bits */ +static inline const char *field_stop(const char *p) +{ + asm( + /* Look for spaces */ + "4: \n\t" + "inc %0 \n\t" + "cmpb $0x20, -1(%0) \n\t" + "ja 4b \n\t" + "jz 3f \n\t" + + /* we only get there for control chars 0..31. Leave if we find '\0' */ + "cmpb $0x0, -1(%0) \n\t" + "jnz 4b \n\t" + + /* return %0-1 = position of the last char we checked */ + "3: \n\t" + "dec %0 \n\t" + : "=r" (p) + : "0" (p) + ); + return p; +} +#else +const char *field_stop(const char *p) +{ + unsigned char c; + + while (1) { + c = *(p++); + if (c > ' ') + continue; + if (c == ' ' || c == 0) + break; + } + return p - 1; +} +#endif + +/* return non-zero if the argument contains at least one zero byte. See principle above. */ +static inline __attribute__((unused)) unsigned long long has_zero64(unsigned long long x) +{ + unsigned long long y; + + y = x - 0x0101010101010101ULL; /* generate a carry */ + y &= ~x; /* clear the bits that were already set */ + return y & 0x8080808080808080ULL; +} + +/* return field <field> (starting from 1) in string <p>. Only consider + * contiguous spaces (or tabs) as one delimiter. May return pointer to + * last char if field is not found. Equivalent to awk '{print $field}'. + */ +const char *field_start(const char *p, int field) +{ +#ifndef PREFER_ASM + unsigned char c; + while (1) { + /* skip spaces */ + while (1) { + c = *(p++); + if (!c) /* end of line */ + return p-1; + if (c == ' ') + continue; + /* other char => new field */ + break; + } + + /* start of field */ + field--; + if (!field) + return p-1; + + /* skip this field */ + while (1) { +#if defined(HA_UNALIGNED_LE64) + unsigned long long l = *(unsigned long long *)p; + if (!has_zero64(l)) { + l ^= 0x2020202020202020; + l = has_zero64(l); + if (!l) { + p += 8; + continue; + } + /* there is at least one space, find it and + * skip it now. The lowest byte in <l> with + * a 0x80 is the right one, but checking for + * it remains slower than testing each byte, + * probably due to the numerous short fields. + */ + while (*(p++) != ' ') + ; + break; + } +#endif + c = *(p++); + if (c == '\0') + return p - 1; + if (c == ' ') + break; + } + } +#else + /* This version works optimally on i386 and x86_64 but the code above + * shows similar performance. However, depending on the version of GCC + * used, inlining rules change and it may have difficulties to make + * efficient use of this code at other locations and could result in + * worse performance (eg: gcc 4.4). You may want to experience. + */ + asm( + /* skip spaces */ + "1: \n\t" + "inc %0 \n\t" + "cmpb $0x20, -1(%0) \n\t" + "ja 2f \n\t" + "jz 1b \n\t" + + /* we only get there for control chars 0..31. Leave if we find '\0' */ + "cmpb $0x0, -1(%0) \n\t" + "jz 3f \n\t" + + /* start of field at [%0-1]. Check if we need to skip more fields */ + "2: \n\t" + "dec %1 \n\t" + "jz 3f \n\t" + + /* Look for spaces */ + "4: \n\t" + "inc %0 \n\t" + "cmpb $0x20, -1(%0) \n\t" + "jz 1b \n\t" + "ja 4b \n\t" + + /* we only get there for control chars 0..31. Leave if we find '\0' */ + "cmpb $0x0, -1(%0) \n\t" + "jnz 4b \n\t" + + /* return %0-1 = position of the last char we checked */ + "3: \n\t" + "dec %0 \n\t" + : "=r" (p) + : "r" (field), "0" (p) + ); + return p; +#endif +} + +/* keep only the <bits> higher bits of <i> */ +static inline unsigned int quantify_u32(unsigned int i, int bits) +{ + int high; + + if (!bits) + return 0; + + if (i) + high = fls_auto(i); // 1 to 32 + else + high = 0; + + if (high <= bits) + return i; + + return i & ~((1 << (high - bits)) - 1); +} + +/* keep only the <bits> higher bits of the absolute value of <i>, as well as + * its sign. */ +static inline int quantify(int i, int bits) +{ + if (i >= 0) + return quantify_u32(i, bits); + else + return -quantify_u32(-i, bits); +} + +/* Insert timer value <v> into tree <r>. A pre-allocated node must be passed + * in <alloc>. It may be NULL, in which case the function will allocate it + * itself. It will be reset to NULL once consumed. The caller is responsible + * for freeing the node once not used anymore. The node where the value was + * inserted is returned. + */ +struct timer *insert_timer(struct eb_root *r, struct timer **alloc, int v) +{ + struct timer *t = *alloc; + struct eb32_node *n; + + if (!t) { + t = calloc(sizeof(*t), 1); + if (unlikely(!t)) { + fprintf(stderr, "%s: not enough memory\n", __FUNCTION__); + exit(1); + } + } + t->node.key = quantify(v, QBITS); // keep only the higher QBITS bits + + n = eb32i_insert(r, &t->node); + if (n == &t->node) + t = NULL; /* node inserted, will malloc next time */ + + *alloc = t; + return container_of(n, struct timer, node); +} + +/* Insert value value <v> into tree <r>. A pre-allocated node must be passed + * in <alloc>. It may be NULL, in which case the function will allocate it + * itself. It will be reset to NULL once consumed. The caller is responsible + * for freeing the node once not used anymore. The node where the value was + * inserted is returned. + */ +struct timer *insert_value(struct eb_root *r, struct timer **alloc, int v) +{ + struct timer *t = *alloc; + struct eb32_node *n; + + if (!t) { + t = calloc(sizeof(*t), 1); + if (unlikely(!t)) { + fprintf(stderr, "%s: not enough memory\n", __FUNCTION__); + exit(1); + } + } + t->node.key = v; + + n = eb32i_insert(r, &t->node); + if (n == &t->node) + t = NULL; /* node inserted, will malloc next time */ + + *alloc = t; + return container_of(n, struct timer, node); +} + +int str2ic(const char *s) +{ + int i = 0; + int j, k; + + if (*s != '-') { + /* positive number */ + while (1) { + j = (*s++) - '0'; + k = i * 10; + if ((unsigned)j > 9) + break; + i = k + j; + } + } else { + /* negative number */ + s++; + while (1) { + j = (*s++) - '0'; + k = i * 10; + if ((unsigned)j > 9) + break; + i = k - j; + } + } + + return i; +} + + +/* Convert "[04/Dec/2008:09:49:40.555]" to an integer equivalent to the time of + * the day in milliseconds. It returns -1 for all unparsable values. The parser + * looks ugly but gcc emits far better code that way. + */ +int convert_date(const char *field) +{ + unsigned int h, m, s, ms; + unsigned char c; + const char *e; + + h = m = s = ms = 0; + e = field; + + /* skip the date */ + while (1) { + c = *(e++); + if (c == ':') + break; + if (!c) + goto out_err; + } + + /* hour + ':' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + h = h * 10 + c; + } + if (c == (unsigned char)(0 - '0')) + goto out_err; + + /* minute + ':' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + m = m * 10 + c; + } + if (c == (unsigned char)(0 - '0')) + goto out_err; + + /* second + '.' or ']' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + s = s * 10 + c; + } + if (c == (unsigned char)(0 - '0')) + goto out_err; + + /* if there's a '.', we have milliseconds */ + if (c == (unsigned char)('.' - '0')) { + /* millisecond second + ']' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + ms = ms * 10 + c; + } + if (c == (unsigned char)(0 - '0')) + goto out_err; + } + return (((h * 60) + m) * 60 + s) * 1000 + ms; + out_err: + return -1; +} + +/* Convert "[04/Dec/2008:09:49:40.555]" to an unix timestamp. + * It returns -1 for all unparsable values. The parser + * looks ugly but gcc emits far better code that way. + */ +int convert_date_to_timestamp(const char *field) +{ + unsigned int d, mo, y, h, m, s; + unsigned char c; + const char *e; + time_t rawtime; + static struct tm * timeinfo; + static int last_res; + + d = mo = y = h = m = s = 0; + e = field; + + e++; // remove '[' + + /* day + '/' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + d = d * 10 + c; + if (c == (unsigned char)(0 - '0')) + goto out_err; + } + + /* month + '/' */ + c = *(e++); + if (c =='F') { + mo = 2; + e = e+3; + } else if (c =='S') { + mo = 9; + e = e+3; + } else if (c =='O') { + mo = 10; + e = e+3; + } else if (c =='N') { + mo = 11; + e = e+3; + } else if (c == 'D') { + mo = 12; + e = e+3; + } else if (c == 'A') { + c = *(e++); + if (c == 'p') { + mo = 4; + e = e+2; + } else if (c == 'u') { + mo = 8; + e = e+2; + } else + goto out_err; + } else if (c == 'J') { + c = *(e++); + if (c == 'a') { + mo = 1; + e = e+2; + } else if (c == 'u') { + c = *(e++); + if (c == 'n') { + mo = 6; + e = e+1; + } else if (c == 'l') { + mo = 7; + e++; + } + } else + goto out_err; + } else if (c == 'M') { + e++; + c = *(e++); + if (c == 'r') { + mo = 3; + e = e+1; + } else if (c == 'y') { + mo = 5; + e = e+1; + } else + goto out_err; + } else + goto out_err; + + /* year + ':' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + y = y * 10 + c; + if (c == (unsigned char)(0 - '0')) + goto out_err; + } + + /* hour + ':' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + h = h * 10 + c; + } + if (c == (unsigned char)(0 - '0')) + goto out_err; + + /* minute + ':' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + m = m * 10 + c; + } + if (c == (unsigned char)(0 - '0')) + goto out_err; + + /* second + '.' or ']' */ + while (1) { + c = *(e++) - '0'; + if (c > 9) + break; + s = s * 10 + c; + } + + if (likely(timeinfo)) { + if ((unsigned)timeinfo->tm_min == m && + (unsigned)timeinfo->tm_hour == h && + (unsigned)timeinfo->tm_mday == d && + (unsigned)timeinfo->tm_mon == mo - 1 && + (unsigned)timeinfo->tm_year == y - 1900) + return last_res + s; + } + else { + time(&rawtime); + timeinfo = localtime(&rawtime); + } + + timeinfo->tm_sec = 0; + timeinfo->tm_min = m; + timeinfo->tm_hour = h; + timeinfo->tm_mday = d; + timeinfo->tm_mon = mo - 1; + timeinfo->tm_year = y - 1900; + last_res = mktime(timeinfo); + + return last_res + s; + out_err: + return -1; +} + +void truncated_line(int linenum, const char *line) +{ + if (!(filter & FILT_QUIET)) + fprintf(stderr, "Truncated line %d: %s\n", linenum, line); +} + +int main(int argc, char **argv) +{ + const char *b, *p, *time_field, *accept_field, *source_field; + const char *filter_term_code_name = NULL; + const char *output_file = NULL; + int f, last; + struct timer *t = NULL; + struct eb32_node *n; + struct url_stat *ustat = NULL; + int val, test; + unsigned int uval; + unsigned int filter_acc_delay = 0, filter_acc_count = 0; + int filter_time_resp = 0; + int filt_http_status_low = 0, filt_http_status_high = 0; + unsigned int filt2_timestamp_low = 0, filt2_timestamp_high = 0; + unsigned int filt2_capture_block = 0, filt2_capture_field = 0; + int skip_fields = 1; + + void (*line_filter)(const char *accept_field, const char *time_field, struct timer **tptr) = NULL; + + argc--; argv++; + while (argc > 0) { + if (*argv[0] != '-') + break; + + if (strcmp(argv[0], "-ad") == 0) { + if (argc < 2) die("missing option for -ad\n"); + argc--; argv++; + filter |= FILT_ACC_DELAY; + filter_acc_delay = atol(*argv); + } + else if (strcmp(argv[0], "-ac") == 0) { + if (argc < 2) die("missing option for -ac\n"); + argc--; argv++; + filter |= FILT_ACC_COUNT; + filter_acc_count = atol(*argv); + } + else if (strcmp(argv[0], "-rt") == 0) { + if (argc < 2) die("missing option for -rt\n"); + argc--; argv++; + filter |= FILT_TIME_RESP; + filter_time_resp = atol(*argv); + } + else if (strcmp(argv[0], "-RT") == 0) { + if (argc < 2) die("missing option for -RT\n"); + argc--; argv++; + filter |= FILT_TIME_RESP | FILT_INVERT_TIME_RESP; + filter_time_resp = atol(*argv); + } + else if (strcmp(argv[0], "-s") == 0) { + if (argc < 2) die("missing option for -s\n"); + argc--; argv++; + skip_fields = atol(*argv); + } + else if (strcmp(argv[0], "-m") == 0) { + if (argc < 2) die("missing option for -m\n"); + argc--; argv++; + lines_max = atol(*argv); + } + else if (strcmp(argv[0], "-e") == 0) + filter |= FILT_ERRORS_ONLY; + else if (strcmp(argv[0], "-E") == 0) + filter |= FILT_ERRORS_ONLY | FILT_INVERT_ERRORS; + else if (strcmp(argv[0], "-H") == 0) + filter |= FILT_HTTP_ONLY; + else if (strcmp(argv[0], "-Q") == 0) + filter |= FILT_QUEUE_ONLY; + else if (strcmp(argv[0], "-QS") == 0) + filter |= FILT_QUEUE_SRV_ONLY; + else if (strcmp(argv[0], "-c") == 0) + filter |= FILT_COUNT_ONLY; + else if (strcmp(argv[0], "-q") == 0) + filter |= FILT_QUIET; + else if (strcmp(argv[0], "-v") == 0) + filter_invert = !filter_invert; + else if (strcmp(argv[0], "-gt") == 0) + filter |= FILT_GRAPH_TIMERS; + else if (strcmp(argv[0], "-pct") == 0) + filter |= FILT_PERCENTILE; + else if (strcmp(argv[0], "-st") == 0) + filter |= FILT_COUNT_STATUS; + else if (strcmp(argv[0], "-srv") == 0) + filter |= FILT_COUNT_SRV_STATUS; + else if (strcmp(argv[0], "-cc") == 0) + filter |= FILT_COUNT_COOK_CODES; + else if (strcmp(argv[0], "-tc") == 0) + filter |= FILT_COUNT_TERM_CODES; + else if (strcmp(argv[0], "-tcn") == 0) { + if (argc < 2) die("missing option for -tcn\n"); + argc--; argv++; + filter |= FILT_TERM_CODE_NAME; + filter_term_code_name = *argv; + } + else if (strcmp(argv[0], "-TCN") == 0) { + if (argc < 2) die("missing option for -TCN\n"); + argc--; argv++; + filter |= FILT_TERM_CODE_NAME | FILT_INVERT_TERM_CODE_NAME; + filter_term_code_name = *argv; + } + else if (strcmp(argv[0], "-hs") == 0 || strcmp(argv[0], "-HS") == 0) { + char *sep, *str; + + if (argc < 2) die("missing option for -hs/-HS ([min]:[max])\n"); + filter |= FILT_HTTP_STATUS; + if (argv[0][1] == 'H') + filter |= FILT_INVERT_HTTP_STATUS; + + argc--; argv++; + str = *argv; + sep = strchr(str, ':'); /* [min]:[max] */ + if (!sep) + sep = str; /* make max point to min */ + else + *sep++ = 0; + filt_http_status_low = *str ? atol(str) : 0; + filt_http_status_high = *sep ? atol(sep) : 65535; + } + else if (strcmp(argv[0], "-time") == 0) { + char *sep, *str; + + if (argc < 2) die("missing option for -time ([min]:[max])\n"); + filter2 |= FILT2_TIMESTAMP; + + argc--; argv++; + str = *argv; + sep = strchr(str, ':'); /* [min]:[max] */ + filt2_timestamp_low = *str ? atol(str) : 0; + if (!sep) + filt2_timestamp_high = 0xFFFFFFFF; + else + filt2_timestamp_high = atol(++sep); + } + else if (strcmp(argv[0], "-u") == 0) + filter |= FILT_COUNT_URL_ONLY; + else if (strcmp(argv[0], "-uc") == 0) + filter |= FILT_COUNT_URL_COUNT; + else if (strcmp(argv[0], "-ue") == 0) + filter |= FILT_COUNT_URL_ERR; + else if (strcmp(argv[0], "-ua") == 0) + filter |= FILT_COUNT_URL_TAVG; + else if (strcmp(argv[0], "-ut") == 0) + filter |= FILT_COUNT_URL_TTOT; + else if (strcmp(argv[0], "-uao") == 0) + filter |= FILT_COUNT_URL_TAVGO; + else if (strcmp(argv[0], "-uto") == 0) + filter |= FILT_COUNT_URL_TTOTO; + else if (strcmp(argv[0], "-uba") == 0) + filter |= FILT_COUNT_URL_BAVG; + else if (strcmp(argv[0], "-ubt") == 0) + filter |= FILT_COUNT_URL_BTOT; + else if (strcmp(argv[0], "-query") == 0) + filter2 |= FILT2_PRESERVE_QUERY; + else if (strcmp(argv[0], "-ic") == 0) + filter |= FILT_COUNT_IP_COUNT; + else if (strcmp(argv[0], "-hdr") == 0) { + char *sep, *str; + + if (argc < 2) die("missing option for -hdr (<block>:<field>)\n"); + filter2 |= FILT2_EXTRACT_CAPTURE; + + argc--; argv++; + str = *argv; + sep = strchr(str, ':'); + if (!sep) + die("missing colon in -hdr (<block>:<field>)\n"); + else + *sep++ = 0; + + filt2_capture_block = *str ? atol(str) : 1; + filt2_capture_field = *sep ? atol(sep) : 1; + + if (filt2_capture_block < 1 || filt2_capture_field < 1) + die("block and field must be at least 1 for -hdr (<block>:<field>)\n"); + } + else if (strcmp(argv[0], "-o") == 0) { + if (output_file) + die("Fatal: output file name already specified.\n"); + if (argc < 2) + die("Fatal: missing output file name.\n"); + output_file = argv[1]; + } + else if (strcmp(argv[0], "-h") == 0 || strcmp(argv[0], "--help") == 0) + help(); + argc--; + argv++; + } + + if (!filter && !filter2) + die("No action specified.\n"); + + if (filter & FILT_ACC_COUNT && !filter_acc_count) + filter_acc_count=1; + + if (filter & FILT_ACC_DELAY && !filter_acc_delay) + filter_acc_delay = 1; + + + /* by default, all lines are printed */ + line_filter = filter_output_line; + if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) + line_filter = filter_accept_holes; + else if (filter & (FILT_GRAPH_TIMERS|FILT_PERCENTILE)) + line_filter = filter_graphs; + else if (filter & FILT_COUNT_STATUS) + line_filter = filter_count_status; + else if (filter & FILT_COUNT_COOK_CODES) + line_filter = filter_count_cook_codes; + else if (filter & FILT_COUNT_TERM_CODES) + line_filter = filter_count_term_codes; + else if (filter & FILT_COUNT_SRV_STATUS) + line_filter = filter_count_srv_status; + else if (filter & FILT_COUNT_URL_ANY) + line_filter = filter_count_url; + else if (filter & FILT_COUNT_ONLY) + line_filter = NULL; + +#if defined(POSIX_FADV_SEQUENTIAL) + /* around 20% performance improvement is observed on Linux with this + * on cold-cache. Surprisingly, WILLNEED is less performant. Don't + * use NOREUSE as it flushes the cache and prevents easy data + * manipulation on logs! + */ + posix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL); +#endif + + if (!line_filter && /* FILT_COUNT_ONLY ( see above), and no input filter (see below) */ + !(filter & (FILT_HTTP_ONLY|FILT_TIME_RESP|FILT_ERRORS_ONLY|FILT_HTTP_STATUS|FILT_QUEUE_ONLY|FILT_QUEUE_SRV_ONLY|FILT_TERM_CODE_NAME)) && + !(filter2 & (FILT2_TIMESTAMP))) { + /* read the whole file at once first, ignore it if inverted output */ + if (!filter_invert) + while ((lines_max < 0 || lines_out < lines_max) && fgets2(stdin) != NULL) + lines_out++; + + goto skip_filters; + } + + while ((line = fgets2(stdin)) != NULL) { + linenum++; + time_field = NULL; accept_field = NULL; + source_field = NULL; + + test = 1; + + /* for any line we process, we first ensure that there is a field + * looking like the accept date field (beginning with a '['). + */ + if (filter & FILT_COUNT_IP_COUNT) { + /* we need the IP first */ + source_field = field_start(line, SOURCE_FIELD + skip_fields); + accept_field = field_start(source_field, ACCEPT_FIELD - SOURCE_FIELD + 1); + } + else + accept_field = field_start(line, ACCEPT_FIELD + skip_fields); + + if (unlikely(*accept_field != '[')) { + parse_err++; + continue; + } + + /* the day of month field is begin 01 and 31 */ + if (accept_field[1] < '0' || accept_field[1] > '3') { + parse_err++; + continue; + } + + if (filter2 & FILT2_TIMESTAMP) { + uval = convert_date_to_timestamp(accept_field); + test &= (uval>=filt2_timestamp_low && uval<=filt2_timestamp_high) ; + } + + if (filter & FILT_HTTP_ONLY) { + /* only report lines with at least 4 timers */ + if (!time_field) { + time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1); + if (unlikely(!*time_field)) { + truncated_line(linenum, line); + continue; + } + } + + field_stop(time_field + 1); + /* we have field TIME_FIELD in [time_field]..[e-1] */ + p = time_field; + f = 0; + while (!SEP(*p)) { + if (++f == 4) + break; + SKIP_CHAR(p, '/'); + } + test &= (f >= 4); + } + + if (filter & FILT_TIME_RESP) { + int tps; + + /* only report lines with response times larger than filter_time_resp */ + if (!time_field) { + time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1); + if (unlikely(!*time_field)) { + truncated_line(linenum, line); + continue; + } + } + + field_stop(time_field + 1); + /* we have field TIME_FIELD in [time_field]..[e-1], let's check only the response time */ + + p = time_field; + f = 0; + while (!SEP(*p)) { + tps = str2ic(p); + if (tps < 0) { + tps = -1; + } + if (++f == 4) + break; + SKIP_CHAR(p, '/'); + } + + if (unlikely(f < 4)) { + parse_err++; + continue; + } + + test &= (tps >= filter_time_resp) ^ !!(filter & FILT_INVERT_TIME_RESP); + } + + if (filter & (FILT_ERRORS_ONLY | FILT_HTTP_STATUS)) { + /* Check both error codes (-1, 5xx) and status code ranges */ + if (time_field) + b = field_start(time_field, STATUS_FIELD - TIME_FIELD + 1); + else + b = field_start(accept_field, STATUS_FIELD - ACCEPT_FIELD + 1); + + if (unlikely(!*b)) { + truncated_line(linenum, line); + continue; + } + + val = str2ic(b); + if (filter & FILT_ERRORS_ONLY) + test &= (val < 0 || (val >= 500 && val <= 599)) ^ !!(filter & FILT_INVERT_ERRORS); + + if (filter & FILT_HTTP_STATUS) + test &= (val >= filt_http_status_low && val <= filt_http_status_high) ^ !!(filter & FILT_INVERT_HTTP_STATUS); + } + + if (filter & (FILT_QUEUE_ONLY|FILT_QUEUE_SRV_ONLY)) { + /* Check if the server's queue is non-nul */ + if (time_field) + b = field_start(time_field, QUEUE_LEN_FIELD - TIME_FIELD + 1); + else + b = field_start(accept_field, QUEUE_LEN_FIELD - ACCEPT_FIELD + 1); + + if (unlikely(!*b)) { + truncated_line(linenum, line); + continue; + } + + if (*b == '0') { + if (filter & FILT_QUEUE_SRV_ONLY) { + test = 0; + } + else { + do { + b++; + if (*b == '/') { + b++; + break; + } + } while (*b); + test &= ((unsigned char)(*b - '1') < 9); + } + } + } + + if (filter & FILT_TERM_CODE_NAME) { + /* only report corresponding termination code name */ + if (time_field) + b = field_start(time_field, TERM_CODES_FIELD - TIME_FIELD + 1); + else + b = field_start(accept_field, TERM_CODES_FIELD - ACCEPT_FIELD + 1); + + if (unlikely(!*b)) { + truncated_line(linenum, line); + continue; + } + + test &= (b[0] == filter_term_code_name[0] && b[1] == filter_term_code_name[1]) ^ !!(filter & FILT_INVERT_TERM_CODE_NAME); + } + + + test ^= filter_invert; + if (!test) + continue; + + /************** here we process inputs *******************/ + + if (line_filter) { + if (filter & FILT_COUNT_IP_COUNT) + filter_count_ip(source_field, accept_field, time_field, &t); + else if (filter2 & FILT2_EXTRACT_CAPTURE) + filter_extract_capture(accept_field, time_field, filt2_capture_block, filt2_capture_field); + else + line_filter(accept_field, time_field, &t); + } + else + lines_out++; /* FILT_COUNT_ONLY was used, so we're just counting lines */ + if (lines_max >= 0 && lines_out >= lines_max) + break; + } + + skip_filters: + /***************************************************** + * Here we've finished reading all input. Depending on the + * filters, we may still have some analysis to run on the + * collected data and to output data in a new format. + *************************************************** */ + + if (t) + free(t); + + if (filter & FILT_COUNT_ONLY) { + printf("%d\n", lines_out); + exit(0); + } + + if (filter & (FILT_ACC_COUNT|FILT_ACC_DELAY)) { + /* sort and count all timers. Output will look like this : + * <accept_date> <delta_ms from previous one> <nb entries> + */ + n = eb32_first(&timers[0]); + + if (n) + last = n->key; + while (n) { + unsigned int d, h, m, s, ms; + + t = container_of(n, struct timer, node); + h = n->key; + d = h - last; + last = h; + + if (d >= filter_acc_delay && t->count >= filter_acc_count) { + ms = h % 1000; h = h / 1000; + s = h % 60; h = h / 60; + m = h % 60; h = h / 60; + printf("%02u:%02u:%02u.%03u %d %u %u\n", h, m, s, ms, last, d, t->count); + lines_out++; + if (lines_max >= 0 && lines_out >= lines_max) + break; + } + n = eb32_next(n); + } + } + else if (filter & FILT_GRAPH_TIMERS) { + /* sort all timers */ + for (f = 0; f < 5; f++) { + struct eb32_node *n; + + n = eb32_first(&timers[f]); + while (n) { + int i; + double d; + int val; + + t = container_of(n, struct timer, node); + last = n->key; + val = t->count; + + i = (last < 0) ? -last : last; + i = fls_auto(i) - QBITS; + + if (i > 0) + d = val / (double)(1 << i); + else + d = val; + + if (d > 0.0) + printf("%d %d %f\n", f, last, d+1.0); + + n = eb32_next(n); + } + } + } + else if (filter & FILT_PERCENTILE) { + /* report timers by percentile : + * <percent> <total> <max_req_time> <max_conn_time> <max_resp_time> <max_data_time> + * We don't count errs. + */ + struct eb32_node *n[5]; + unsigned long cum[5]; + double step; + + if (!lines_out) + goto empty; + + for (f = 1; f < 5; f++) { + n[f] = eb32_first(&timers[f]); + cum[f] = container_of(n[f], struct timer, node)->count; + } + + for (step = 1; step <= 1000;) { + unsigned int thres = lines_out * (step / 1000.0); + + printf("%3.1f %u ", step/10.0, thres); + for (f = 1; f < 5; f++) { + struct eb32_node *next; + while (cum[f] < thres) { + /* need to find other keys */ + next = eb32_next(n[f]); + if (!next) + break; + n[f] = next; + cum[f] += container_of(next, struct timer, node)->count; + } + + /* value still within $step % of total */ + printf("%d ", n[f]->key); + } + putchar('\n'); + if (step >= 100 && step < 900) + step += 50; // jump 5% by 5% between those steps. + else if (step >= 20 && step < 980) + step += 10; + else + step += 1; + } + } + else if (filter & FILT_COUNT_STATUS) { + /* output all statuses in the form of <status> <occurrences> */ + n = eb32_first(&timers[0]); + while (n) { + t = container_of(n, struct timer, node); + printf("%d %u\n", n->key, t->count); + lines_out++; + if (lines_max >= 0 && lines_out >= lines_max) + break; + n = eb32_next(n); + } + } + else if (filter & FILT_COUNT_SRV_STATUS) { + struct ebmb_node *srv_node; + struct srv_st *srv; + + printf("#srv_name 1xx 2xx 3xx 4xx 5xx other tot_req req_ok pct_ok avg_ct avg_rt\n"); + + srv_node = ebmb_first(&timers[0]); + while (srv_node) { + int tot_rq; + + srv = container_of(srv_node, struct srv_st, node); + + tot_rq = 0; + for (f = 0; f <= 5; f++) + tot_rq += srv->st_cnt[f]; + + printf("%s %u %u %u %u %u %u %d %u %.1f %d %d\n", + srv_node->key, srv->st_cnt[1], srv->st_cnt[2], + srv->st_cnt[3], srv->st_cnt[4], srv->st_cnt[5], srv->st_cnt[0], + tot_rq, + srv->nb_ok, (double)srv->nb_ok * 100.0 / (tot_rq?tot_rq:1), + (int)(srv->cum_ct / (srv->nb_ct?srv->nb_ct:1)), (int)(srv->cum_rt / (srv->nb_rt?srv->nb_rt:1))); + srv_node = ebmb_next(srv_node); + lines_out++; + if (lines_max >= 0 && lines_out >= lines_max) + break; + } + } + else if (filter & (FILT_COUNT_TERM_CODES|FILT_COUNT_COOK_CODES)) { + /* output all statuses in the form of <code> <occurrences> */ + n = eb32_first(&timers[0]); + while (n) { + t = container_of(n, struct timer, node); + printf("%c%c %u\n", (n->key >> 8), (n->key) & 255, t->count); + lines_out++; + if (lines_max >= 0 && lines_out >= lines_max) + break; + n = eb32_next(n); + } + } + else if (filter & (FILT_COUNT_URL_ANY|FILT_COUNT_IP_COUNT)) { + struct eb_node *node, *next; + + if (!(filter & FILT_COUNT_URL_ONLY)) { + /* we have to sort on another criterion. We'll use timers[1] for the + * destination tree. + */ + + timers[1] = EB_ROOT; /* reconfigure to accept duplicates */ + for (node = eb_first(&timers[0]); node; node = next) { + next = eb_next(node); + eb_delete(node); + + ustat = container_of(node, struct url_stat, node.url.node); + + if (filter & (FILT_COUNT_URL_COUNT|FILT_COUNT_IP_COUNT)) + ustat->node.val.key = ustat->nb_req; + else if (filter & FILT_COUNT_URL_ERR) + ustat->node.val.key = ustat->nb_err; + else if (filter & FILT_COUNT_URL_TTOT) + ustat->node.val.key = ustat->total_time; + else if (filter & FILT_COUNT_URL_TAVG) + ustat->node.val.key = ustat->nb_req ? ustat->total_time / ustat->nb_req : 0; + else if (filter & FILT_COUNT_URL_TTOTO) + ustat->node.val.key = ustat->total_time_ok; + else if (filter & FILT_COUNT_URL_TAVGO) + ustat->node.val.key = (ustat->nb_req - ustat->nb_err) ? ustat->total_time_ok / (ustat->nb_req - ustat->nb_err) : 0; + else if (filter & FILT_COUNT_URL_BAVG) + ustat->node.val.key = ustat->nb_req ? ustat->total_bytes_sent / ustat->nb_req : 0; + else if (filter & FILT_COUNT_URL_BTOT) + ustat->node.val.key = ustat->total_bytes_sent; + else + ustat->node.val.key = 0; + + eb64_insert(&timers[1], &ustat->node.val); + } + /* switch trees */ + timers[0] = timers[1]; + } + + if (FILT_COUNT_IP_COUNT) + printf("#req err ttot tavg oktot okavg bavg btot src\n"); + else + printf("#req err ttot tavg oktot okavg bavg btot url\n"); + + /* scan the tree in its reverse sorting order */ + node = eb_last(&timers[0]); + while (node) { + ustat = container_of(node, struct url_stat, node.url.node); + printf("%u %u %llu %llu %llu %llu %llu %llu %s\n", + ustat->nb_req, + ustat->nb_err, + ustat->total_time, + ustat->nb_req ? ustat->total_time / ustat->nb_req : 0, + ustat->total_time_ok, + (ustat->nb_req - ustat->nb_err) ? ustat->total_time_ok / (ustat->nb_req - ustat->nb_err) : 0, + ustat->nb_req ? ustat->total_bytes_sent / ustat->nb_req : 0, + ustat->total_bytes_sent, + ustat->url); + + node = eb_prev(node); + lines_out++; + if (lines_max >= 0 && lines_out >= lines_max) + break; + } + } + + empty: + if (!(filter & FILT_QUIET)) + fprintf(stderr, "%d lines in, %d lines out, %d parsing errors\n", + linenum, lines_out, parse_err); + exit(0); +} + +void filter_output_line(const char *accept_field, const char *time_field, struct timer **tptr) +{ + puts(line); + lines_out++; +} + +void filter_extract_capture(const char *accept_field, const char *time_field, unsigned int block, unsigned int field) +{ + const char *e, *f; + + if (time_field) + e = field_start(time_field, METH_FIELD - TIME_FIELD + 1); + else + e = field_start(accept_field, METH_FIELD - ACCEPT_FIELD + 1); + + while (block-- > 0) { + /* Scan until the start of a capture block ('{') until the URL ('"'). */ + while ((*e != '"' && *e != '{') && *e) { + /* Note: some syslog servers escape quotes ! */ + if (*e == '\\' && e[1] == '"') + break; + + e = field_start(e, 2); + } + + if (unlikely(!*e)) { + truncated_line(linenum, line); + return; + } + + /* We reached the URL, no more captures will follow. */ + if (*e != '{') { + puts(""); + lines_out++; + return; + } + + /* e points the the opening brace of the capture block. */ + + e++; + } + + /* We are in the first field of the selected capture block. */ + + while (--field > 0) { + while ((*e != '|' && *e != '}') && *e) + e++; + + if (unlikely(!*e)) { + truncated_line(linenum, line); + return; + } + + if (*e != '|') { + puts(""); + lines_out++; + return; + } + + /* e points to the pipe. */ + + e++; + } + + f = e; + + while ((*f != '|' && *f != '}') && *f) + f++; + + if (unlikely(!*f)) { + truncated_line(linenum, line); + return; + } + + fwrite(e, f - e, 1, stdout); + putchar('\n'); + lines_out++; +} + +void filter_accept_holes(const char *accept_field, const char *time_field, struct timer **tptr) +{ + struct timer *t2; + int val; + + val = convert_date(accept_field); + if (unlikely(val < 0)) { + truncated_line(linenum, line); + return; + } + + t2 = insert_value(&timers[0], tptr, val); + t2->count++; + return; +} + +void filter_count_status(const char *accept_field, const char *time_field, struct timer **tptr) +{ + struct timer *t2; + const char *b; + int val; + + if (time_field) + b = field_start(time_field, STATUS_FIELD - TIME_FIELD + 1); + else + b = field_start(accept_field, STATUS_FIELD - ACCEPT_FIELD + 1); + + if (unlikely(!*b)) { + truncated_line(linenum, line); + return; + } + + val = str2ic(b); + + t2 = insert_value(&timers[0], tptr, val); + t2->count++; +} + +void filter_count_cook_codes(const char *accept_field, const char *time_field, struct timer **tptr) +{ + struct timer *t2; + const char *b; + int val; + + if (time_field) + b = field_start(time_field, TERM_CODES_FIELD - TIME_FIELD + 1); + else + b = field_start(accept_field, TERM_CODES_FIELD - ACCEPT_FIELD + 1); + + if (unlikely(!*b)) { + truncated_line(linenum, line); + return; + } + + val = 256 * b[2] + b[3]; + + t2 = insert_value(&timers[0], tptr, val); + t2->count++; +} + +void filter_count_term_codes(const char *accept_field, const char *time_field, struct timer **tptr) +{ + struct timer *t2; + const char *b; + int val; + + if (time_field) + b = field_start(time_field, TERM_CODES_FIELD - TIME_FIELD + 1); + else + b = field_start(accept_field, TERM_CODES_FIELD - ACCEPT_FIELD + 1); + + if (unlikely(!*b)) { + truncated_line(linenum, line); + return; + } + + val = 256 * b[0] + b[1]; + + t2 = insert_value(&timers[0], tptr, val); + t2->count++; +} + +void filter_count_srv_status(const char *accept_field, const char *time_field, struct timer **tptr) +{ + const char *b, *e, *p; + int f, err, array[5]; + struct ebmb_node *srv_node; + struct srv_st *srv; + int val; + + /* the server field is before the status field, so let's + * parse them in the proper order. + */ + b = field_start(accept_field, SERVER_FIELD - ACCEPT_FIELD + 1); + if (unlikely(!*b)) { + truncated_line(linenum, line); + return; + } + + e = field_stop(b + 1); /* we have the server name in [b]..[e-1] */ + + /* the chance that a server name already exists is extremely high, + * so let's perform a normal lookup first. + */ + srv_node = ebst_lookup_len(&timers[0], b, e - b); + srv = container_of(srv_node, struct srv_st, node); + + if (!srv_node) { + /* server not yet in the tree, let's create it */ + srv = (void *)calloc(1, sizeof(struct srv_st) + e - b + 1); + srv_node = &srv->node; + memcpy(&srv_node->key, b, e - b); + srv_node->key[e - b] = '\0'; + ebst_insert(&timers[0], srv_node); + } + + /* let's collect the connect and response times */ + if (!time_field) { + time_field = field_start(e, TIME_FIELD - SERVER_FIELD); + if (unlikely(!*time_field)) { + truncated_line(linenum, line); + return; + } + } + + e = field_stop(time_field + 1); + /* we have field TIME_FIELD in [time_field]..[e-1] */ + + p = time_field; + err = 0; + f = 0; + while (!SEP(*p)) { + array[f] = str2ic(p); + if (array[f] < 0) { + array[f] = -1; + err = 1; + } + if (++f == 5) + break; + SKIP_CHAR(p, '/'); + } + + if (unlikely(f < 5)){ + parse_err++; + return; + } + + /* OK we have our timers in array[2,3] */ + if (!err) + srv->nb_ok++; + + if (array[2] >= 0) { + srv->cum_ct += array[2]; + srv->nb_ct++; + } + + if (array[3] >= 0) { + srv->cum_rt += array[3]; + srv->nb_rt++; + } + + /* we're interested in the 5 HTTP status classes (1xx ... 5xx), and + * the invalid ones which will be reported as 0. + */ + b = field_start(e, STATUS_FIELD - TIME_FIELD); + if (unlikely(!*b)) { + truncated_line(linenum, line); + return; + } + + val = 0; + if (*b >= '1' && *b <= '5') + val = *b - '0'; + + srv->st_cnt[val]++; +} + +void filter_count_url(const char *accept_field, const char *time_field, struct timer **tptr) +{ + struct url_stat *ustat = NULL; + struct ebpt_node *ebpt_old; + const char *b, *e; + int f, err, array[5]; + int val; + + /* let's collect the response time */ + if (!time_field) { + time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1); // avg 115 ns per line + if (unlikely(!*time_field)) { + truncated_line(linenum, line); + return; + } + } + + /* we have the field TIME_FIELD starting at <time_field>. We'll + * parse the 5 timers to detect errors, it takes avg 55 ns per line. + */ + e = time_field; err = 0; f = 0; + while (!SEP(*e)) { + array[f] = str2ic(e); + if (array[f] < 0) { + array[f] = -1; + err = 1; + } + if (++f == 5) + break; + SKIP_CHAR(e, '/'); + } + if (f < 5) { + parse_err++; + return; + } + + /* OK we have our timers in array[3], and err is >0 if at + * least one -1 was seen. <e> points to the first char of + * the last timer. Let's prepare a new node with that. + */ + if (unlikely(!ustat)) + ustat = calloc(1, sizeof(*ustat)); + + ustat->nb_err = err; + ustat->nb_req = 1; + + /* use array[4] = total time in case of error */ + ustat->total_time = (array[3] >= 0) ? array[3] : array[4]; + ustat->total_time_ok = (array[3] >= 0) ? array[3] : 0; + + e = field_start(e, BYTES_SENT_FIELD - TIME_FIELD + 1); + val = str2ic(e); + ustat->total_bytes_sent = val; + + /* the line may be truncated because of a bad request or anything like this, + * without a method. Also, if it does not begin with an quote, let's skip to + * the next field because it's a capture. Let's fall back to the "method" itself + * if there's nothing else. + */ + e = field_start(e, METH_FIELD - BYTES_SENT_FIELD + 1); + while (*e != '"' && *e) { + /* Note: some syslog servers escape quotes ! */ + if (*e == '\\' && e[1] == '"') + break; + e = field_start(e, 2); + } + + if (unlikely(!*e)) { + truncated_line(linenum, line); + free(ustat); + return; + } + + b = field_start(e, URL_FIELD - METH_FIELD + 1); // avg 40 ns per line + if (!*b) + b = e; + + /* stop at end of field or first ';' or '?', takes avg 64 ns per line */ + e = b; + do { + if (*e == ' '|| + (!(filter2 & FILT2_PRESERVE_QUERY) && (*e == '?' || *e == ';'))) { + *(char *)e = 0; + break; + } + e++; + } while (*e); + + /* now instead of copying the URL for a simple lookup, we'll link + * to it from the node we're trying to insert. If it returns a + * different value, it was already there. Otherwise we just have + * to dynamically realloc an entry using strdup(). + */ + ustat->node.url.key = (char *)b; + ebpt_old = ebis_insert(&timers[0], &ustat->node.url); + + if (ebpt_old != &ustat->node.url) { + struct url_stat *ustat_old; + /* node was already there, let's update previous one */ + ustat_old = container_of(ebpt_old, struct url_stat, node.url); + ustat_old->nb_req ++; + ustat_old->nb_err += ustat->nb_err; + ustat_old->total_time += ustat->total_time; + ustat_old->total_time_ok += ustat->total_time_ok; + ustat_old->total_bytes_sent += ustat->total_bytes_sent; + } else { + ustat->url = ustat->node.url.key = strdup(ustat->node.url.key); + ustat = NULL; /* node was used */ + } +} + +void filter_count_ip(const char *source_field, const char *accept_field, const char *time_field, struct timer **tptr) +{ + struct url_stat *ustat = NULL; + struct ebpt_node *ebpt_old; + const char *b, *e; + int f, err, array[5]; + int val; + + /* let's collect the response time */ + if (!time_field) { + time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1); // avg 115 ns per line + if (unlikely(!*time_field)) { + truncated_line(linenum, line); + return; + } + } + + /* we have the field TIME_FIELD starting at <time_field>. We'll + * parse the 5 timers to detect errors, it takes avg 55 ns per line. + */ + e = time_field; err = 0; f = 0; + while (!SEP(*e)) { + if (f == 0 || f == 4) { + array[f] = str2ic(e); + if (array[f] < 0) { + array[f] = -1; + err = 1; + } + } + if (++f == 5) + break; + SKIP_CHAR(e, '/'); + } + if (f < 5) { + parse_err++; + return; + } + + /* OK we have our timers in array[0], and err is >0 if at + * least one -1 was seen. <e> points to the first char of + * the last timer. Let's prepare a new node with that. + */ + if (unlikely(!ustat)) + ustat = calloc(1, sizeof(*ustat)); + + ustat->nb_err = err; + ustat->nb_req = 1; + + /* use array[4] = total time in case of error */ + ustat->total_time = (array[0] >= 0) ? array[0] : array[4]; + ustat->total_time_ok = (array[0] >= 0) ? array[0] : 0; + + e = field_start(e, BYTES_SENT_FIELD - TIME_FIELD + 1); + val = str2ic(e); + ustat->total_bytes_sent = val; + + /* the source might be IPv4 or IPv6, so we always strip the port by + * removing the last colon. + */ + b = source_field; + e = field_stop(b + 1); + while (e > b && e[-1] != ':') + e--; + *(char *)(e - 1) = '\0'; + + /* now instead of copying the src for a simple lookup, we'll link + * to it from the node we're trying to insert. If it returns a + * different value, it was already there. Otherwise we just have + * to dynamically realloc an entry using strdup(). We're using the + * <url> field of the node to store the source address. + */ + ustat->node.url.key = (char *)b; + ebpt_old = ebis_insert(&timers[0], &ustat->node.url); + + if (ebpt_old != &ustat->node.url) { + struct url_stat *ustat_old; + /* node was already there, let's update previous one */ + ustat_old = container_of(ebpt_old, struct url_stat, node.url); + ustat_old->nb_req ++; + ustat_old->nb_err += ustat->nb_err; + ustat_old->total_time += ustat->total_time; + ustat_old->total_time_ok += ustat->total_time_ok; + ustat_old->total_bytes_sent += ustat->total_bytes_sent; + } else { + ustat->url = ustat->node.url.key = strdup(ustat->node.url.key); + ustat = NULL; /* node was used */ + } +} + +void filter_graphs(const char *accept_field, const char *time_field, struct timer **tptr) +{ + struct timer *t2; + const char *p; + int f, err, array[5]; + + if (!time_field) { + time_field = field_start(accept_field, TIME_FIELD - ACCEPT_FIELD + 1); + if (unlikely(!*time_field)) { + truncated_line(linenum, line); + return; + } + } + + field_stop(time_field + 1); + /* we have field TIME_FIELD in [time_field]..[e-1] */ + + p = time_field; + err = 0; + f = 0; + while (!SEP(*p)) { + array[f] = str2ic(p); + if (array[f] < 0) { + array[f] = -1; + err = 1; + } + if (++f == 5) + break; + SKIP_CHAR(p, '/'); + } + + if (unlikely(f < 5)) { + parse_err++; + return; + } + + /* if we find at least one negative time, we count one error + * with a time equal to the total session time. This will + * emphasize quantum timing effects associated to known + * timeouts. Note that on some buggy machines, it is possible + * that the total time is negative, hence the reason to reset + * it. + */ + + if (filter & FILT_GRAPH_TIMERS) { + if (err) { + if (array[4] < 0) + array[4] = -1; + t2 = insert_timer(&timers[0], tptr, array[4]); // total time + t2->count++; + } else { + int v; + + t2 = insert_timer(&timers[1], tptr, array[0]); t2->count++; // req + t2 = insert_timer(&timers[2], tptr, array[2]); t2->count++; // conn + t2 = insert_timer(&timers[3], tptr, array[3]); t2->count++; // resp + + v = array[4] - array[0] - array[1] - array[2] - array[3]; // data time + if (v < 0 && !(filter & FILT_QUIET)) + fprintf(stderr, "ERR: %s (%d %d %d %d %d => %d)\n", + line, array[0], array[1], array[2], array[3], array[4], v); + t2 = insert_timer(&timers[4], tptr, v); t2->count++; + lines_out++; + } + } else { /* percentile */ + if (err) { + if (array[4] < 0) + array[4] = -1; + t2 = insert_value(&timers[0], tptr, array[4]); // total time + t2->count++; + } else { + int v; + + t2 = insert_value(&timers[1], tptr, array[0]); t2->count++; // req + t2 = insert_value(&timers[2], tptr, array[2]); t2->count++; // conn + t2 = insert_value(&timers[3], tptr, array[3]); t2->count++; // resp + + v = array[4] - array[0] - array[1] - array[2] - array[3]; // data time + if (v < 0 && !(filter & FILT_QUIET)) + fprintf(stderr, "ERR: %s (%d %d %d %d %d => %d)\n", + line, array[0], array[1], array[2], array[3], array[4], v); + t2 = insert_value(&timers[4], tptr, v); t2->count++; + lines_out++; + } + } +} + + +/* + * Local variables: + * c-indent-level: 8 + * c-basic-offset: 8 + * End: + */ diff --git a/admin/iprange/Makefile b/admin/iprange/Makefile new file mode 100644 index 0000000..13598d8 --- /dev/null +++ b/admin/iprange/Makefile @@ -0,0 +1,13 @@ +CC = cc +OPTIMIZE = -O3 +LDFLAGS = -s + +OBJS = iprange ip6range + +all: $(OBJS) + +%: %.c + $(CC) $(LDFLAGS) $(OPTIMIZE) -o $@ $^ + +clean: + rm -f $(OBJS) *.o *.a *~ diff --git a/admin/iprange/ip6range.c b/admin/iprange/ip6range.c new file mode 100644 index 0000000..2ffd490 --- /dev/null +++ b/admin/iprange/ip6range.c @@ -0,0 +1,397 @@ +/* + * network range to IP+mask converter + * + * Copyright 2011-2012 Willy Tarreau <w@1wt.eu> + * + * This program reads lines starting by two IP addresses and outputs them with + * the two IP addresses replaced by a netmask covering the range between these + * IPs (inclusive). When multiple ranges are needed, as many lines are emitted. + * The IP addresses may be delimited by spaces, tabs or commas. Quotes are + * stripped, and lines beginning with a sharp character ('#') are ignored. The + * IP addresses may be either in the dotted format or represented as a 32-bit + * integer value in network byte order. + * + * This program 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 + * 2 of the License, or (at your option) any later version. + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define MAXLINE 1024 + +static inline void in6_bswap(struct in6_addr *a) +{ + a->s6_addr32[0] = ntohl(a->s6_addr32[0]); + a->s6_addr32[1] = ntohl(a->s6_addr32[1]); + a->s6_addr32[2] = ntohl(a->s6_addr32[2]); + a->s6_addr32[3] = ntohl(a->s6_addr32[3]); +} + +/* returns a string version of an IPv6 address in host order */ +static const char *get_ipv6_addr(struct in6_addr *addr) +{ + struct in6_addr a; + static char out[INET6_ADDRSTRLEN + 1]; + + memcpy(&a, addr, sizeof(struct in6_addr)); + in6_bswap(&a); + return inet_ntop(AF_INET6, &a, out, INET6_ADDRSTRLEN + 1); +} + +static const char *get_addr(struct in6_addr *addr) +{ + static char out[50]; + snprintf(out, 50, "%08x:%08x:%08x:%08x", + addr->s6_addr32[0], + addr->s6_addr32[1], + addr->s6_addr32[2], + addr->s6_addr32[3]); + return out; +} + +/* a <= b */ +static inline int a_le_b(struct in6_addr *a, struct in6_addr *b) +{ + if (a->s6_addr32[0] < b->s6_addr32[0]) return 1; + if (a->s6_addr32[0] > b->s6_addr32[0]) return 0; + if (a->s6_addr32[1] < b->s6_addr32[1]) return 1; + if (a->s6_addr32[1] > b->s6_addr32[1]) return 0; + if (a->s6_addr32[2] < b->s6_addr32[2]) return 1; + if (a->s6_addr32[2] > b->s6_addr32[2]) return 0; + if (a->s6_addr32[3] < b->s6_addr32[3]) return 1; + if (a->s6_addr32[3] > b->s6_addr32[3]) return 0; + return 1; +} + +/* a == b */ +static inline int a_eq_b(struct in6_addr *a, struct in6_addr *b) +{ + if (a->s6_addr32[0] != b->s6_addr32[0]) return 0; + if (a->s6_addr32[1] != b->s6_addr32[1]) return 0; + if (a->s6_addr32[2] != b->s6_addr32[2]) return 0; + if (a->s6_addr32[3] != b->s6_addr32[3]) return 0; + return 1; +} + +/* a > b */ +static inline int a_gt_b(struct in6_addr *a, struct in6_addr *b) +{ + if (a->s6_addr32[0] > b->s6_addr32[0]) return 1; + if (a->s6_addr32[0] < b->s6_addr32[0]) return 0; + if (a->s6_addr32[1] > b->s6_addr32[1]) return 1; + if (a->s6_addr32[1] < b->s6_addr32[1]) return 0; + if (a->s6_addr32[2] > b->s6_addr32[2]) return 1; + if (a->s6_addr32[2] < b->s6_addr32[2]) return 0; + if (a->s6_addr32[3] > b->s6_addr32[3]) return 1; + if (a->s6_addr32[3] < b->s6_addr32[3]) return 0; + return 0; +} + +/* ( 1 << m ) - 1 -> r */ +static inline struct in6_addr *hmask(unsigned int b, struct in6_addr *r) +{ + + if (b < 32) { + r->s6_addr32[3] = (1 << b) - 1; + r->s6_addr32[2] = 0; + r->s6_addr32[1] = 0; + r->s6_addr32[0] = 0; + } + else if (b < 64) { + r->s6_addr32[3] = 0xffffffff; + r->s6_addr32[2] = (1 << (b - 32)) - 1; + r->s6_addr32[1] = 0; + r->s6_addr32[0] = 0; + } + else if (b < 96) { + r->s6_addr32[3] = 0xffffffff; + r->s6_addr32[2] = 0xffffffff; + r->s6_addr32[1] = (1 << (b - 64)) - 1; + r->s6_addr32[0] = 0; + } + else if (b < 128) { + r->s6_addr32[3] = 0xffffffff; + r->s6_addr32[2] = 0xffffffff; + r->s6_addr32[1] = 0xffffffff; + r->s6_addr32[0] = (1 << (b - 96)) - 1; + } + else { + r->s6_addr32[3] = 0xffffffff; + r->s6_addr32[2] = 0xffffffff; + r->s6_addr32[1] = 0xffffffff; + r->s6_addr32[0] = 0xffffffff; + } + return r; +} + +/* 1 << b -> r */ +static inline struct in6_addr *one_ls_b(unsigned int b, struct in6_addr *r) +{ + if (b < 32) { + r->s6_addr32[3] = 1 << b; + r->s6_addr32[2] = 0; + r->s6_addr32[1] = 0; + r->s6_addr32[0] = 0; + } + else if (b < 64) { + r->s6_addr32[3] = 0; + r->s6_addr32[2] = 1 << (b - 32); + r->s6_addr32[1] = 0; + r->s6_addr32[0] = 0; + } + else if (b < 96) { + r->s6_addr32[3] = 0; + r->s6_addr32[2] = 0; + r->s6_addr32[1] = 1 << (b - 64); + r->s6_addr32[0] = 0; + } + else if (b < 128) { + r->s6_addr32[3] = 0; + r->s6_addr32[2] = 0; + r->s6_addr32[1] = 0; + r->s6_addr32[0] = 1 << (b - 96); + } + else { + r->s6_addr32[3] = 0; + r->s6_addr32[2] = 0; + r->s6_addr32[1] = 0; + r->s6_addr32[0] = 0; + } + return r; +} + +/* a + b -> r */ +static inline struct in6_addr *a_plus_b(struct in6_addr *a, struct in6_addr *b, struct in6_addr *r) +{ + unsigned long long int c = 0; + int i; + + for (i=3; i>=0; i--) { + c = (unsigned long long int)a->s6_addr32[i] + + (unsigned long long int)b->s6_addr32[i] + c; + r->s6_addr32[i] = c; + c >>= 32; + } + + return r; +} + +/* a - b -> r */ +static inline struct in6_addr *a_minus_b(struct in6_addr *a, struct in6_addr *b, struct in6_addr *r) +{ + signed long long int c = 0; + signed long long int d; + int i; + + /* Check sign. Return 0xff..ff (-1) if the result is less than 0. */ + if (a_gt_b(b, a)) { + r->s6_addr32[3] = 0xffffffff; + r->s6_addr32[2] = 0xffffffff; + r->s6_addr32[1] = 0xffffffff; + r->s6_addr32[0] = 0xffffffff; + return r; + } + + for (i=3; i>=0; i--) { + d = (unsigned long long int)b->s6_addr32[i] + c; + c = (unsigned long long int)a->s6_addr32[i]; + if (c < d) + c += 0x100000000ULL; + c -= d; + r->s6_addr32[i] = c; + c >>= 32; + } + + return r; +} + +/* a & b -> r */ +static inline struct in6_addr *a_and_b(struct in6_addr *a, struct in6_addr *b, struct in6_addr *r) +{ + r->s6_addr32[0] = a->s6_addr32[0] & b->s6_addr32[0]; + r->s6_addr32[1] = a->s6_addr32[1] & b->s6_addr32[1]; + r->s6_addr32[2] = a->s6_addr32[2] & b->s6_addr32[2]; + r->s6_addr32[3] = a->s6_addr32[3] & b->s6_addr32[3]; + return r; +} + +/* a != 0 */ +int is_set(struct in6_addr *a) +{ + return a->s6_addr32[0] || + a->s6_addr32[1] || + a->s6_addr32[2] || + a->s6_addr32[3]; +} + +/* 1 */ +static struct in6_addr one = { .s6_addr32 = {0, 0, 0, 1} }; + +/* print all networks present between address <low> and address <high> in + * cidr format, followed by <eol>. + */ +static void convert_range(struct in6_addr *low, struct in6_addr *high, const char *eol, const char *pfx) +{ + int bit; + struct in6_addr r0; + struct in6_addr r1; + + if (a_eq_b(low, high)) { + /* single value */ + printf("%s%s%s%s\n", pfx?pfx:"", pfx?" ":"", get_ipv6_addr(low), eol); + return; + } + else if (a_gt_b(low, high)) { + struct in6_addr *swap = low; + low = high; + high = swap; + } + + if (a_eq_b(low, a_plus_b(high, &one, &r0))) { + /* full range */ + printf("%s%s::/0%s\n", pfx?pfx:"", pfx?" ":"", eol); + return; + } + //printf("low=%08x high=%08x\n", low, high); + + bit = 0; + while (bit < 128 && a_le_b(a_plus_b(low, hmask(bit, &r0), &r0), high)) { + + /* enlarge mask */ + if (is_set(a_and_b(low, one_ls_b(bit, &r0), &r0))) { + /* can't aggregate anymore, dump and retry from the same bit */ + printf("%s%s%s/%d%s\n", pfx?pfx:"", pfx?" ":"", get_ipv6_addr(low), 128-bit, eol); + a_plus_b(low, one_ls_b(bit, &r0), low); + } + else { + /* try to enlarge the mask as much as possible first */ + bit++; + //printf(" ++bit=%d\n", bit); + } + } + //printf("stopped 1 at low=%08x, bit=%d\n", low, bit); + + bit = 127; + while (bit >= 0 && is_set(a_plus_b(a_minus_b(high, low, &r0), &one, &r0))) { + + /* shrink mask */ + if (is_set(a_and_b(a_plus_b(a_minus_b(high, low, &r0), &one, &r0), one_ls_b(bit, &r1), &r1))) { + /* large bit accepted, dump and go on from the same bit */ + //printf("max: %08x/%d\n", low, 32-bit); + printf("%s%s%s/%d%s\n", pfx?pfx:"", pfx?" ":"", get_ipv6_addr(low), 128-bit, eol); + a_plus_b(low, one_ls_b(bit, &r0), low); + } + else { + bit--; + //printf(" --bit=%d, low=%08x\n", bit, low); + } + } + //printf("stopped at low=%08x\n", low); +} + +static void usage(const char *argv0) +{ + fprintf(stderr, + "Usage: %s [<addr> ...] < iplist.csv\n" + "\n" + "This program reads lines starting by two IP addresses and outputs them with\n" + "the two IP addresses replaced by a netmask covering the range between these\n" + "IPs (inclusive). When multiple ranges are needed, as many lines are emitted.\n" + "The IP addresses may be delimited by spaces, tabs or commas. Quotes are\n" + "stripped, and lines beginning with a sharp character ('#') are ignored. The\n" + "IP addresses may be either in the dotted format or represented as a 32-bit\n" + "integer value in network byte order.\n" + "\n" + "For each optional <addr> specified, only the network it belongs to is returned,\n" + "prefixed with the <addr> value.\n" + "\n", argv0); +} + +int main(int argc, char **argv) +{ + char line[MAXLINE]; + int l, lnum; + char *lb, *le, *hb, *he, *err; + struct in6_addr sa, da, ta; + + if (argc > 1 && *argv[1] == '-') { + usage(argv[0]); + exit(1); + } + + lnum = 0; + while (fgets(line, sizeof(line), stdin) != NULL) { + l = strlen(line); + if (l && line[l - 1] == '\n') + line[--l] = '\0'; + + lnum++; + /* look for the first field which must be the low address of a range, + * in dotted IPv4 format or as an integer. spaces and commas are + * considered as delimiters, quotes are removed. + */ + for (lb = line; *lb == ' ' || *lb == '\t' || *lb == ',' || *lb == '"'; lb++); + if (!*lb || *lb == '#') + continue; + for (le = lb + 1; *le != ' ' && *le != '\t' && *le != ',' && *le != '"' && *le; le++); + if (!*le) + continue; + /* we have the low address between lb(included) and le(excluded) */ + *(le++) = 0; + + for (hb = le; *hb == ' ' || *hb == '\t' || *hb == ',' || *hb == '"'; hb++); + if (!*hb || *hb == '#') + continue; + for (he = hb + 1; *he != ' ' && *he != '\t' && *he != ',' && *he != '"' && *he; he++); + if (!*he) + continue; + /* we have the high address between hb(included) and he(excluded) */ + *(he++) = 0; + + /* we want to remove a possible ending quote and a possible comma, + * not more. + */ + while (*he == '"') + *(he++) = ' '; + while (*he == ',' || *he == ' ' || *he == '\t') + *(he++) = ' '; + + /* if the trailing string is not empty, prefix it with a space */ + if (*(he-1) == ' ') + he--; + + if (inet_pton(AF_INET6, lb, &sa) <= 0) { + fprintf(stderr, "Failed to parse source address <%s> at line %d, skipping line\n", lb, lnum); + continue; + } + + if (inet_pton(AF_INET6, hb, &da) <= 0) { + fprintf(stderr, "Failed to parse destination address <%s> at line %d, skipping line\n", hb, lnum); + continue; + } + + in6_bswap(&sa); + in6_bswap(&da); + + if (argc > 1) { + for (l = 1; l < argc; l++) { + if (inet_pton(AF_INET6, argv[l], &da) <= 0) + continue; + in6_bswap(&ta); + if ((a_le_b(&sa, &ta) && a_le_b(&ta, &da)) || (a_le_b(&da, &ta) && a_le_b(&ta, &sa))) + convert_range(&sa, &da, he, argv[l]); + } + } + else { + convert_range(&sa, &da, he, NULL); + } + } + return 0; +} diff --git a/admin/iprange/iprange.c b/admin/iprange/iprange.c new file mode 100644 index 0000000..abae007 --- /dev/null +++ b/admin/iprange/iprange.c @@ -0,0 +1,202 @@ +/* + * network range to IP+mask converter + * + * Copyright 2011-2012 Willy Tarreau <w@1wt.eu> + * + * This program reads lines starting by two IP addresses and outputs them with + * the two IP addresses replaced by a netmask covering the range between these + * IPs (inclusive). When multiple ranges are needed, as many lines are emitted. + * The IP addresses may be delimited by spaces, tabs or commas. Quotes are + * stripped, and lines beginning with a sharp character ('#') are ignored. The + * IP addresses may be either in the dotted format or represented as a 32-bit + * integer value in network byte order. + * + * This program 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 + * 2 of the License, or (at your option) any later version. + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define MAXLINE 1024 + +/* returns a string version of an IPv4 address in host order */ +static const char *get_ipv4_addr(unsigned int addr) +{ + struct in_addr a; + + a.s_addr = ntohl(addr); + return inet_ntoa(a); +} + +/* print all networks present between address <low> and address <high> in + * cidr format, followed by <eol>. + */ +static void convert_range(unsigned int low, unsigned int high, const char *eol, const char *pfx) +{ + int bit; + + if (low == high) { + /* single value */ + printf("%s%s%s%s\n", pfx?pfx:"", pfx?" ":"", get_ipv4_addr(low), eol); + return; + } + else if (low > high) { + int swap = low; + low = high; + high = swap; + } + + if (low == high + 1) { + /* full range */ + printf("%s%s0.0.0.0/0%s\n", pfx?pfx:"", pfx?" ":"", eol); + return; + } + //printf("low=%08x high=%08x\n", low, high); + + bit = 0; + while (bit < 32 && low + (1 << bit) - 1 <= high) { + /* enlarge mask */ + if (low & (1 << bit)) { + /* can't aggregate anymore, dump and retry from the same bit */ + printf("%s%s%s/%d%s\n", pfx?pfx:"", pfx?" ":"", get_ipv4_addr(low), 32-bit, eol); + low += (1 << bit); + } + else { + /* try to enlarge the mask as much as possible first */ + bit++; + //printf(" ++bit=%d\n", bit); + } + } + //printf("stopped 1 at low=%08x, bit=%d\n", low, bit); + + bit = 31; + while (bit >= 0 && high - low + 1 != 0) { + /* shrink mask */ + if ((high - low + 1) & (1 << bit)) { + /* large bit accepted, dump and go on from the same bit */ + //printf("max: %08x/%d\n", low, 32-bit); + printf("%s%s%s/%d%s\n", pfx?pfx:"", pfx?" ":"", get_ipv4_addr(low), 32-bit, eol); + low += (1 << bit); + } + else { + bit--; + //printf(" --bit=%d, low=%08x\n", bit, low); + } + } + //printf("stopped at low=%08x\n", low); +} + +static void usage(const char *argv0) +{ + fprintf(stderr, + "Usage: %s [<addr> ...] < iplist.csv\n" + "\n" + "This program reads lines starting by two IP addresses and outputs them with\n" + "the two IP addresses replaced by a netmask covering the range between these\n" + "IPs (inclusive). When multiple ranges are needed, as many lines are emitted.\n" + "The IP addresses may be delimited by spaces, tabs or commas. Quotes are\n" + "stripped, and lines beginning with a sharp character ('#') are ignored. The\n" + "IP addresses may be either in the dotted format or represented as a 32-bit\n" + "integer value in network byte order.\n" + "\n" + "For each optional <addr> specified, only the network it belongs to is returned,\n" + "prefixed with the <addr> value.\n" + "\n", argv0); +} + +int main(int argc, char **argv) +{ + char line[MAXLINE]; + int l, lnum; + char *lb, *le, *hb, *he, *err; + struct in_addr src_addr, dst_addr; + unsigned int sa, da, ta; + + if (argc > 1 && *argv[1] == '-') { + usage(argv[0]); + exit(1); + } + + lnum = 0; + while (fgets(line, sizeof(line), stdin) != NULL) { + l = strlen(line); + if (l && line[l - 1] == '\n') + line[--l] = '\0'; + + lnum++; + /* look for the first field which must be the low address of a range, + * in dotted IPv4 format or as an integer. spaces and commas are + * considered as delimiters, quotes are removed. + */ + for (lb = line; *lb == ' ' || *lb == '\t' || *lb == ',' || *lb == '"'; lb++); + if (!*lb || *lb == '#') + continue; + for (le = lb + 1; *le != ' ' && *le != '\t' && *le != ',' && *le != '"' && *le; le++); + if (!*le) + continue; + /* we have the low address between lb(included) and le(excluded) */ + *(le++) = 0; + + for (hb = le; *hb == ' ' || *hb == '\t' || *hb == ',' || *hb == '"'; hb++); + if (!*hb || *hb == '#') + continue; + for (he = hb + 1; *he != ' ' && *he != '\t' && *he != ',' && *he != '"' && *he; he++); + if (!*he) + continue; + /* we have the high address between hb(included) and he(excluded) */ + *(he++) = 0; + + /* we want to remove a possible ending quote and a possible comma, + * not more. + */ + while (*he == '"') + *(he++) = ' '; + while (*he == ',' || *he == ' ' || *he == '\t') + *(he++) = ' '; + + /* if the trailing string is not empty, prefix it with a space */ + if (*(he-1) == ' ') + he--; + + if (inet_pton(AF_INET, lb, &src_addr) <= 0) { + /* parsing failed, retry with a plain numeric IP */ + src_addr.s_addr = ntohl(strtoul(lb, &err, 10)); + if (err && *err) { + fprintf(stderr, "Failed to parse source address <%s> at line %d, skipping line\n", lb, lnum); + continue; + } + } + + if (inet_pton(AF_INET, hb, &dst_addr) <= 0) { + /* parsing failed, retry with a plain numeric IP */ + dst_addr.s_addr = ntohl(strtoul(hb, &err, 10)); + if (err && *err) { + fprintf(stderr, "Failed to parse destination address <%s> at line %d, skipping line\n", hb, lnum); + continue; + } + } + + sa = htonl(src_addr.s_addr); + da = htonl(dst_addr.s_addr); + if (argc > 1) { + for (l = 1; l < argc; l++) { + if (inet_pton(AF_INET, argv[l], &dst_addr) <= 0) + continue; + ta = htonl(dst_addr.s_addr); + if ((sa <= ta && ta <= da) || (da <= ta && ta <= sa)) + convert_range(sa, da, he, argv[l]); + } + } + else { + convert_range(sa, da, he, NULL); + } + } + exit(0); +} diff --git a/admin/netsnmp-perl/README b/admin/netsnmp-perl/README new file mode 100644 index 0000000..f44eb5b --- /dev/null +++ b/admin/netsnmp-perl/README @@ -0,0 +1,111 @@ +SNMP support for HAProxy +Copyright 2007-2008 Krzysztof Piotr Oledzki <ole@ans.pl> + +Root OID: 1.3.6.1.4.1.29385.106 + +Files: + - README: this file + - haproxy.pl: Net-SNMP embedded perl module + - haproxy_backend.xml: Cacti snmp-query definition for backends + - haproxy_frontend.xml: Cacti snmp-query definition for frontends + +Install: + cp haproxy.pl /etc/snmp/ + grep -q "disablePerl false" /etc/snmp/snmpd.conf || echo "disablePerl false" >> /etc/snmp/snmpd.conf + echo "perl do '/etc/snmp/haproxy.pl';" >> /etc/snmp/snmpd.conf + +Supported commands: + - GET (snmpget, snmpbulkget): quite fast. + - GETNEXT (snmpwalk, snmpbulkwalk): not so fast as requires to transfer + and parse a lot of data during each step. Always use "get" instead of "walk" + if that's possible. + +Supported OIDs: + - 1.3.6.1.4.1.29385.106.1: get a variable from stats + Usage: 1.3.6.1.4.1.29385.106.1.$type.$field.$iid.$sid + + - type is one of: + 0) frontend + 1) backend + 2) server + + - field is one of: + 0..32) CSV format variable + 10001) index + 10002) unique name + + - iid is a proxy id + + - sid is a service id (sid): 0 for frontends and backends, >= 1 for servers + + - 1.3.6.1.4.1.29385.106.2: get a variable from info + Usage: 1.3.6.1.4.1.29385.106.2.$req.$varnr + + - req is one of: + 0) get variable name + 1) gat variable value + +Examples: + +- Get a list of frontends (type: 0) with status (field: 17): +$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.1.0.17 +SNMPv2-SMI::enterprises.29385.106.1.0.17.1.0 = STRING: "OPEN" +SNMPv2-SMI::enterprises.29385.106.1.0.17.47.0 = STRING: "OPEN" + +- Get a list of backends (type: 1) with index (field: 10001): +$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.1.1.10001 +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1.0 = STRING: "1.0" +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1100.0 = STRING: "1100.0" +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1101.0 = STRING: "1101.0" +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1200.0 = STRING: "1200.0" +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1201.0 = STRING: "1201.0" +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1300.0 = STRING: "1300.0" +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1400.0 = STRING: "1400.0" +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1401.0 = STRING: "1401.0" +SNMPv2-SMI::enterprises.29385.106.1.1.10001.1500.0 = STRING: "1500.0" +(...) + +- Get a list of servers (type: 2) with unique name (field: 10002): +$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.1.2.10002 +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1100.1001 = STRING: "backend1/s2" +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1100.1002 = STRING: "backend1/s5" +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1100.1003 = STRING: "backend1/s6" +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1100.1012 = STRING: "backend1/s7" +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1101.1001 = STRING: "backend2/s9" +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1101.1002 = STRING: "backend2/s10" +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1101.1003 = STRING: "backend2/s11" +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1101.1012 = STRING: "backend2/s12" +SNMPv2-SMI::enterprises.29385.106.1.2.10002.1200.1001 = STRING: "backend3/s8" +(...) + +- Get a list of servers (type: 2) with weight (field: 18) in proxy 4300: +$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.1.2.18.4300 +SNMPv2-SMI::enterprises.29385.106.1.2.18.4300.1001 = STRING: "40" +SNMPv2-SMI::enterprises.29385.106.1.2.18.4300.1002 = STRING: "25" +SNMPv2-SMI::enterprises.29385.106.1.2.18.4300.1003 = STRING: "40" +SNMPv2-SMI::enterprises.29385.106.1.2.18.4300.1012 = STRING: "80" + +- Get total sessions count (field: 7) in frontend (type: 1), sid.iid: 47.0 (proxy #47): +snmpget -c public -v2c 192.168.0.1 enterprises.29385.106.1.0.7.47.0 +SNMPv2-SMI::enterprises.29385.106.1.0.7.47.0 = STRING: "1014019" + +- Get a list of available variables (req: 0): +$ snmpbulkwalk -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.2.0 +SNMPv2-SMI::enterprises.29385.106.2.0.0 = STRING: "Name" +SNMPv2-SMI::enterprises.29385.106.2.0.1 = STRING: "Version" +SNMPv2-SMI::enterprises.29385.106.2.0.2 = STRING: "Release_date" +SNMPv2-SMI::enterprises.29385.106.2.0.3 = STRING: "Nbproc" +SNMPv2-SMI::enterprises.29385.106.2.0.4 = STRING: "Process_num" +SNMPv2-SMI::enterprises.29385.106.2.0.5 = STRING: "Pid" +SNMPv2-SMI::enterprises.29385.106.2.0.6 = STRING: "Uptime" +SNMPv2-SMI::enterprises.29385.106.2.0.7 = STRING: "Uptime_sec" +SNMPv2-SMI::enterprises.29385.106.2.0.8 = STRING: "Memmax_MB" +SNMPv2-SMI::enterprises.29385.106.2.0.9 = STRING: "Ulimit-n" +SNMPv2-SMI::enterprises.29385.106.2.0.10 = STRING: "Maxsock" +SNMPv2-SMI::enterprises.29385.106.2.0.11 = STRING: "Maxconn" +SNMPv2-SMI::enterprises.29385.106.2.0.12 = STRING: "CurrConns" + +- Get a variable (req: 1), varnr: 7 (Uptime_sec): +$ snmpget -c public -v2c 192.168.0.1 1.3.6.1.4.1.29385.106.2.1.7 +SNMPv2-SMI::enterprises.29385.106.2.1.7 = STRING: "18761" + diff --git a/admin/netsnmp-perl/cacti_data_query_haproxy_backends.xml b/admin/netsnmp-perl/cacti_data_query_haproxy_backends.xml new file mode 100644 index 0000000..9c4ea38 --- /dev/null +++ b/admin/netsnmp-perl/cacti_data_query_haproxy_backends.xml @@ -0,0 +1,750 @@ +<cacti> + <hash_040013d1dd43e3e5cee941860ea277826c4fe2> + <name>HaProxy Backends</name> + <description></description> + <xml_path><path_cacti>/resource/snmp_queries/haproxy_backend.xml</xml_path> + <data_input_id>hash_030013bf566c869ac6443b0c75d1c32b5a350e</data_input_id> + <graphs> + <hash_1100134d2954fa52f51ed186916f2cf624a8b9> + <name>HAProxy Backend Sessions</name> + <graph_template_id>hash_000013cdbf9accfcd57d9e0a7c97896313ddee</graph_template_id> + <rrd> + <item_000> + <snmp_field_name>beSTot</snmp_field_name> + <data_template_id>hash_010013fa4d4fff334b60e9064e89082173fe34</data_template_id> + <data_template_rrd_id>hash_080013230e04055a4228154123e74c6586d435</data_template_rrd_id> + </item_000> + <item_001> + <snmp_field_name>beEResp</snmp_field_name> + <data_template_id>hash_010013fa4d4fff334b60e9064e89082173fe34</data_template_id> + <data_template_rrd_id>hash_080013088549c8d7e8cdc80f19bae4d78dc296</data_template_rrd_id> + </item_001> + </rrd> + <sv_graph> + <hash_12001368ff8a0bfc447cb94d02e0d17cc3e252> + <field_name>ResponseErrors</field_name> + <sequence>1</sequence> + <text>ResponseErrors</text> + </hash_12001368ff8a0bfc447cb94d02e0d17cc3e252> + <hash_120013c2e81996ac5a70f67fa4a07e95eea035> + <field_name>TotalSessions</field_name> + <sequence>1</sequence> + <text>TotalSessions</text> + </hash_120013c2e81996ac5a70f67fa4a07e95eea035> + </sv_graph> + <sv_data_source> + <hash_130013169b7ea71d2aa3a8abaece19de7feeff> + <field_name>ResponseErrors</field_name> + <data_template_id>hash_010013fa4d4fff334b60e9064e89082173fe34</data_template_id> + <sequence>1</sequence> + <text>ResponseErrors</text> + </hash_130013169b7ea71d2aa3a8abaece19de7feeff> + <hash_130013a61ea1bb051f2162ba635c815324678d> + <field_name>TotalSessions</field_name> + <data_template_id>hash_010013fa4d4fff334b60e9064e89082173fe34</data_template_id> + <sequence>1</sequence> + <text>TotalSessions</text> + </hash_130013a61ea1bb051f2162ba635c815324678d> + </sv_data_source> + </hash_1100134d2954fa52f51ed186916f2cf624a8b9> + <hash_110013abc35ade0aae030d90f817dfd91486f4> + <name>HAProxy Backend Traffic</name> + <graph_template_id>hash_000013b6d238ff2532fcc19ab498043c7c65c2</graph_template_id> + <rrd> + <item_000> + <snmp_field_name>beBOut</snmp_field_name> + <data_template_id>hash_010013a63ddba34026d2c07d73c0ef2ae64b54</data_template_id> + <data_template_rrd_id>hash_0800136c0e4debeb9b084231d858faabd82f8f</data_template_rrd_id> + </item_000> + <item_001> + <snmp_field_name>beBIn</snmp_field_name> + <data_template_id>hash_010013a63ddba34026d2c07d73c0ef2ae64b54</data_template_id> + <data_template_rrd_id>hash_0800132f5283f17a7cde63137189d4d3ea7e4e</data_template_rrd_id> + </item_001> + </rrd> + <sv_graph> + <hash_1200133ba4a6c8aacf161f3e2411afd7053b8d> + <field_name>BytesIn</field_name> + <sequence>1</sequence> + <text>BytesIn</text> + </hash_1200133ba4a6c8aacf161f3e2411afd7053b8d> + <hash_1200130f8f674b52f6ea2e09608b505abfb3a1> + <field_name>BytesOut</field_name> + <sequence>1</sequence> + <text>BytesOut</text> + </hash_1200130f8f674b52f6ea2e09608b505abfb3a1> + </sv_graph> + <sv_data_source> + <hash_130013d9fb3064081d77e553c5ce732f15c909> + <field_name>BytesIn</field_name> + <data_template_id>hash_010013fa4d4fff334b60e9064e89082173fe34</data_template_id> + <sequence>1</sequence> + <text>BytesIn</text> + </hash_130013d9fb3064081d77e553c5ce732f15c909> + <hash_1300134fc96e4392a7a86d05fda31c2d5d334c> + <field_name>BytesOut</field_name> + <data_template_id>hash_010013fa4d4fff334b60e9064e89082173fe34</data_template_id> + <sequence>1</sequence> + <text>BytesOut</text> + </hash_1300134fc96e4392a7a86d05fda31c2d5d334c> + <hash_130013a7aad3557880ac197539a1d658f5d5da> + <field_name>BytesIn</field_name> + <data_template_id>hash_010013a63ddba34026d2c07d73c0ef2ae64b54</data_template_id> + <sequence>1</sequence> + <text>BytesIn</text> + </hash_130013a7aad3557880ac197539a1d658f5d5da> + <hash_130013acb469b673f6adbaa21ad5c634c3683f> + <field_name>BytesOut</field_name> + <data_template_id>hash_010013a63ddba34026d2c07d73c0ef2ae64b54</data_template_id> + <sequence>1</sequence> + <text>BytesOut</text> + </hash_130013acb469b673f6adbaa21ad5c634c3683f> + </sv_data_source> + </hash_110013abc35ade0aae030d90f817dfd91486f4> + </graphs> + </hash_040013d1dd43e3e5cee941860ea277826c4fe2> + <hash_030013bf566c869ac6443b0c75d1c32b5a350e> + <name>Get SNMP Data (Indexed)</name> + <type_id>3</type_id> + <input_string></input_string> + <fields> + <hash_070013617cdc8a230615e59f06f361ef6e7728> + <name>SNMP IP Address</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>hostname</type_code> + <input_output>in</input_output> + <data_name>management_ip</data_name> + </hash_070013617cdc8a230615e59f06f361ef6e7728> + <hash_070013acb449d1451e8a2a655c2c99d31142c7> + <name>SNMP Community</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>snmp_community</type_code> + <input_output>in</input_output> + <data_name>snmp_community</data_name> + </hash_070013acb449d1451e8a2a655c2c99d31142c7> + <hash_070013f4facc5e2ca7ebee621f09bc6d9fc792> + <name>SNMP Username (v3)</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls>on</allow_nulls> + <type_code>snmp_username</type_code> + <input_output>in</input_output> + <data_name>snmp_username</data_name> + </hash_070013f4facc5e2ca7ebee621f09bc6d9fc792> + <hash_0700131cc1493a6781af2c478fa4de971531cf> + <name>SNMP Password (v3)</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls>on</allow_nulls> + <type_code>snmp_password</type_code> + <input_output>in</input_output> + <data_name>snmp_password</data_name> + </hash_0700131cc1493a6781af2c478fa4de971531cf> + <hash_070013b5c23f246559df38662c255f4aa21d6b> + <name>SNMP Version (1, 2, or 3)</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>snmp_version</type_code> + <input_output>in</input_output> + <data_name>snmp_version</data_name> + </hash_070013b5c23f246559df38662c255f4aa21d6b> + <hash_0700136027a919c7c7731fbe095b6f53ab127b> + <name>Index Type</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>index_type</type_code> + <input_output>in</input_output> + <data_name>index_type</data_name> + </hash_0700136027a919c7c7731fbe095b6f53ab127b> + <hash_070013cbbe5c1ddfb264a6e5d509ce1c78c95f> + <name>Index Value</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>index_value</type_code> + <input_output>in</input_output> + <data_name>index_value</data_name> + </hash_070013cbbe5c1ddfb264a6e5d509ce1c78c95f> + <hash_070013e6deda7be0f391399c5130e7c4a48b28> + <name>Output Type ID</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>output_type</type_code> + <input_output>in</input_output> + <data_name>output_type</data_name> + </hash_070013e6deda7be0f391399c5130e7c4a48b28> + <hash_070013c1f36ee60c3dc98945556d57f26e475b> + <name>SNMP Port</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>snmp_port</type_code> + <input_output>in</input_output> + <data_name>snmp_port</data_name> + </hash_070013c1f36ee60c3dc98945556d57f26e475b> + </fields> + </hash_030013bf566c869ac6443b0c75d1c32b5a350e> + <hash_000013cdbf9accfcd57d9e0a7c97896313ddee> + <name>HAProxy Backend Sessions</name> + <graph> + <t_title></t_title> + <title>|host_description| - HaProxy - |query_bePxName| Backend Sessions</title> + <t_image_format_id></t_image_format_id> + <image_format_id>1</image_format_id> + <t_height></t_height> + <height>120</height> + <t_width></t_width> + <width>500</width> + <t_auto_scale></t_auto_scale> + <auto_scale>on</auto_scale> + <t_auto_scale_opts></t_auto_scale_opts> + <auto_scale_opts>2</auto_scale_opts> + <t_auto_scale_log></t_auto_scale_log> + <auto_scale_log></auto_scale_log> + <t_auto_scale_rigid></t_auto_scale_rigid> + <auto_scale_rigid></auto_scale_rigid> + <t_auto_padding></t_auto_padding> + <auto_padding>on</auto_padding> + <t_export></t_export> + <export>on</export> + <t_upper_limit></t_upper_limit> + <upper_limit>10000</upper_limit> + <t_lower_limit></t_lower_limit> + <lower_limit>0</lower_limit> + <t_base_value></t_base_value> + <base_value>1000</base_value> + <t_unit_value></t_unit_value> + <unit_value></unit_value> + <t_unit_exponent_value></t_unit_exponent_value> + <unit_exponent_value></unit_exponent_value> + <t_vertical_label></t_vertical_label> + <vertical_label></vertical_label> + </graph> + <items> + <hash_1000131ecaf3728447913a30dfa80cdd9cdff4> + <task_item_id>hash_080013230e04055a4228154123e74c6586d435</task_item_id> + <color_id>0000FF</color_id> + <graph_type_id>5</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Total Sessions:</text_format> + <hard_return></hard_return> + <sequence>5</sequence> + </hash_1000131ecaf3728447913a30dfa80cdd9cdff4> + <hash_1000132171a00b34d33f99ef24bcc235fbb6a3> + <task_item_id>hash_080013230e04055a4228154123e74c6586d435</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>4</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Current:</text_format> + <hard_return></hard_return> + <sequence>6</sequence> + </hash_1000132171a00b34d33f99ef24bcc235fbb6a3> + <hash_1000132129590e72a46480422f85e063d8cf4d> + <task_item_id>hash_080013230e04055a4228154123e74c6586d435</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Average:</text_format> + <hard_return></hard_return> + <sequence>7</sequence> + </hash_1000132129590e72a46480422f85e063d8cf4d> + <hash_1000138d11fec869f88ccf2fa3227bcffadfc3> + <task_item_id>hash_080013230e04055a4228154123e74c6586d435</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>3</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Maximum:</text_format> + <hard_return>on</hard_return> + <sequence>8</sequence> + </hash_1000138d11fec869f88ccf2fa3227bcffadfc3> + <hash_100013783d295131617ad996e4699533a134ea> + <task_item_id>hash_080013088549c8d7e8cdc80f19bae4d78dc296</task_item_id> + <color_id>EA8F00</color_id> + <graph_type_id>5</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Response Errors:</text_format> + <hard_return></hard_return> + <sequence>9</sequence> + </hash_100013783d295131617ad996e4699533a134ea> + <hash_1000139bc04e5072b25ca992ee0b0eec981b95> + <task_item_id>hash_080013088549c8d7e8cdc80f19bae4d78dc296</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>4</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Current:</text_format> + <hard_return></hard_return> + <sequence>10</sequence> + </hash_1000139bc04e5072b25ca992ee0b0eec981b95> + <hash_1000136333a9334fa0dc0d2f75c031dee1dcc5> + <task_item_id>hash_080013088549c8d7e8cdc80f19bae4d78dc296</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Average:</text_format> + <hard_return></hard_return> + <sequence>11</sequence> + </hash_1000136333a9334fa0dc0d2f75c031dee1dcc5> + <hash_10001386e0e18d79915cd21ff123fb830e150e> + <task_item_id>hash_080013088549c8d7e8cdc80f19bae4d78dc296</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>3</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Maximum:</text_format> + <hard_return>on</hard_return> + <sequence>12</sequence> + </hash_10001386e0e18d79915cd21ff123fb830e150e> + <hash_100013206b0b016daf267ff0a1daa7733ecf25> + <task_item_id>0</task_item_id> + <color_id>0</color_id> + <graph_type_id>1</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Graph Last Updated: |date_time|</text_format> + <hard_return>on</hard_return> + <sequence>13</sequence> + </hash_100013206b0b016daf267ff0a1daa7733ecf25> + </items> + <inputs> + <hash_090013871102d568ae1a0d7d79aa4b0d3a6411> + <name>Data Source [TotalSessions]</name> + <description></description> + <column_name>task_item_id</column_name> + <items>hash_0000131ecaf3728447913a30dfa80cdd9cdff4|hash_0000132171a00b34d33f99ef24bcc235fbb6a3|hash_0000132129590e72a46480422f85e063d8cf4d|hash_0000138d11fec869f88ccf2fa3227bcffadfc3</items> + </hash_090013871102d568ae1a0d7d79aa4b0d3a6411> + <hash_090013320fd0edeb30465be51274fa3ecbe168> + <name>Data Source [ResponseErrors]</name> + <description></description> + <column_name>task_item_id</column_name> + <items>hash_000013783d295131617ad996e4699533a134ea|hash_0000139bc04e5072b25ca992ee0b0eec981b95|hash_0000136333a9334fa0dc0d2f75c031dee1dcc5|hash_00001386e0e18d79915cd21ff123fb830e150e</items> + </hash_090013320fd0edeb30465be51274fa3ecbe168> + </inputs> + </hash_000013cdbf9accfcd57d9e0a7c97896313ddee> + <hash_000013b6d238ff2532fcc19ab498043c7c65c2> + <name>HAProxy Backend Traffic</name> + <graph> + <t_title></t_title> + <title>|host_description| - HaProxy |query_bePxName| Backend Traffic</title> + <t_image_format_id></t_image_format_id> + <image_format_id>1</image_format_id> + <t_height></t_height> + <height>120</height> + <t_width></t_width> + <width>500</width> + <t_auto_scale></t_auto_scale> + <auto_scale>on</auto_scale> + <t_auto_scale_opts></t_auto_scale_opts> + <auto_scale_opts>2</auto_scale_opts> + <t_auto_scale_log></t_auto_scale_log> + <auto_scale_log></auto_scale_log> + <t_auto_scale_rigid></t_auto_scale_rigid> + <auto_scale_rigid></auto_scale_rigid> + <t_auto_padding></t_auto_padding> + <auto_padding>on</auto_padding> + <t_export></t_export> + <export>on</export> + <t_upper_limit></t_upper_limit> + <upper_limit>10000000000</upper_limit> + <t_lower_limit></t_lower_limit> + <lower_limit>0</lower_limit> + <t_base_value></t_base_value> + <base_value>1024</base_value> + <t_unit_value></t_unit_value> + <unit_value></unit_value> + <t_unit_exponent_value></t_unit_exponent_value> + <unit_exponent_value></unit_exponent_value> + <t_vertical_label></t_vertical_label> + <vertical_label>bytes</vertical_label> + </graph> + <items> + <hash_100013184e60d8dac2421c2787887fe07f6d25> + <task_item_id>hash_0800132f5283f17a7cde63137189d4d3ea7e4e</task_item_id> + <color_id>6EA100</color_id> + <graph_type_id>5</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Ingress Traffic:</text_format> + <hard_return></hard_return> + <sequence>2</sequence> + </hash_100013184e60d8dac2421c2787887fe07f6d25> + <hash_100013f3889b4094b935798483e489b5f5e16e> + <task_item_id>hash_0800132f5283f17a7cde63137189d4d3ea7e4e</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>4</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Current:</text_format> + <hard_return></hard_return> + <sequence>3</sequence> + </hash_100013f3889b4094b935798483e489b5f5e16e> + <hash_1000134bbdf263db6461f5d76717c12564c42c> + <task_item_id>hash_0800132f5283f17a7cde63137189d4d3ea7e4e</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Average:</text_format> + <hard_return></hard_return> + <sequence>4</sequence> + </hash_1000134bbdf263db6461f5d76717c12564c42c> + <hash_1000131b708578244e36caba0f4dea67230c80> + <task_item_id>hash_0800132f5283f17a7cde63137189d4d3ea7e4e</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>3</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Maximum:</text_format> + <hard_return>on</hard_return> + <sequence>5</sequence> + </hash_1000131b708578244e36caba0f4dea67230c80> + <hash_1000133e2f02edb1a55bcdd20e925a3849fd37> + <task_item_id>hash_0800136c0e4debeb9b084231d858faabd82f8f</task_item_id> + <color_id>FF0000</color_id> + <graph_type_id>5</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Egress Traffic:</text_format> + <hard_return></hard_return> + <sequence>6</sequence> + </hash_1000133e2f02edb1a55bcdd20e925a3849fd37> + <hash_1000134517c9799c71e03dcd2278681858d70f> + <task_item_id>hash_0800136c0e4debeb9b084231d858faabd82f8f</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>4</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Current:</text_format> + <hard_return></hard_return> + <sequence>7</sequence> + </hash_1000134517c9799c71e03dcd2278681858d70f> + <hash_1000132edf24a4592c9537d2341ec20c588fc2> + <task_item_id>hash_0800136c0e4debeb9b084231d858faabd82f8f</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Average:</text_format> + <hard_return></hard_return> + <sequence>8</sequence> + </hash_1000132edf24a4592c9537d2341ec20c588fc2> + <hash_100013150e680935bfccc75f1f88c7c60030f7> + <task_item_id>hash_0800136c0e4debeb9b084231d858faabd82f8f</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>3</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Maximum:</text_format> + <hard_return>on</hard_return> + <sequence>9</sequence> + </hash_100013150e680935bfccc75f1f88c7c60030f7> + <hash_1000135dcb7625a1a21d8d94fdf2f97d302a42> + <task_item_id>0</task_item_id> + <color_id>0</color_id> + <graph_type_id>1</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Graph Last Updated: |date_time|</text_format> + <hard_return>on</hard_return> + <sequence>10</sequence> + </hash_1000135dcb7625a1a21d8d94fdf2f97d302a42> + </items> + <inputs> + <hash_090013952f2971b58b10f88a55d63a0388a429> + <name>Data Source [BytesIn]</name> + <description></description> + <column_name>task_item_id</column_name> + <items>hash_000013184e60d8dac2421c2787887fe07f6d25|hash_000013f3889b4094b935798483e489b5f5e16e|hash_0000134bbdf263db6461f5d76717c12564c42c|hash_0000131b708578244e36caba0f4dea67230c80</items> + </hash_090013952f2971b58b10f88a55d63a0388a429> + <hash_09001393a65aa111654d6801846a6cb523580b> + <name>Data Source [BytesOut]</name> + <description></description> + <column_name>task_item_id</column_name> + <items>hash_0000133e2f02edb1a55bcdd20e925a3849fd37|hash_0000134517c9799c71e03dcd2278681858d70f|hash_0000132edf24a4592c9537d2341ec20c588fc2|hash_000013150e680935bfccc75f1f88c7c60030f7</items> + </hash_09001393a65aa111654d6801846a6cb523580b> + </inputs> + </hash_000013b6d238ff2532fcc19ab498043c7c65c2> + <hash_010013fa4d4fff334b60e9064e89082173fe34> + <name>HAProxy Backend Session Stats</name> + <ds> + <t_name></t_name> + <name>|host_description| - HAProxy - |query_bePxName| Backend Session Stats</name> + <data_input_id>hash_030013bf566c869ac6443b0c75d1c32b5a350e</data_input_id> + <t_rra_id></t_rra_id> + <t_rrd_step></t_rrd_step> + <rrd_step>300</rrd_step> + <t_active></t_active> + <active>on</active> + <rra_items>hash_150013c21df5178e5c955013591239eb0afd46|hash_1500130d9c0af8b8acdc7807943937b3208e29|hash_1500136fc2d038fb42950138b0ce3e9874cc60|hash_150013e36f3adb9f152adfa5dc50fd2b23337e|hash_15001352829408ab566127eede2c74d201c678|hash_150013e73fb797d3ab2a9b97c3ec29e9690910</rra_items> + </ds> + <items> + <hash_080013230e04055a4228154123e74c6586d435> + <t_data_source_name></t_data_source_name> + <data_source_name>TotalSessions</data_source_name> + <t_rrd_minimum></t_rrd_minimum> + <rrd_minimum>0</rrd_minimum> + <t_rrd_maximum></t_rrd_maximum> + <rrd_maximum>10000</rrd_maximum> + <t_data_source_type_id></t_data_source_type_id> + <data_source_type_id>2</data_source_type_id> + <t_rrd_heartbeat></t_rrd_heartbeat> + <rrd_heartbeat>600</rrd_heartbeat> + <t_data_input_field_id></t_data_input_field_id> + <data_input_field_id>0</data_input_field_id> + </hash_080013230e04055a4228154123e74c6586d435> + <hash_080013088549c8d7e8cdc80f19bae4d78dc296> + <t_data_source_name></t_data_source_name> + <data_source_name>ResponseErrors</data_source_name> + <t_rrd_minimum></t_rrd_minimum> + <rrd_minimum>0</rrd_minimum> + <t_rrd_maximum></t_rrd_maximum> + <rrd_maximum>10000</rrd_maximum> + <t_data_source_type_id></t_data_source_type_id> + <data_source_type_id>2</data_source_type_id> + <t_rrd_heartbeat></t_rrd_heartbeat> + <rrd_heartbeat>600</rrd_heartbeat> + <t_data_input_field_id></t_data_input_field_id> + <data_input_field_id>0</data_input_field_id> + </hash_080013088549c8d7e8cdc80f19bae4d78dc296> + </items> + <data> + <item_000> + <data_input_field_id>hash_070013c1f36ee60c3dc98945556d57f26e475b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_000> + <item_001> + <data_input_field_id>hash_070013e6deda7be0f391399c5130e7c4a48b28</data_input_field_id> + <t_value></t_value> + <value></value> + </item_001> + <item_002> + <data_input_field_id>hash_070013cbbe5c1ddfb264a6e5d509ce1c78c95f</data_input_field_id> + <t_value></t_value> + <value></value> + </item_002> + <item_003> + <data_input_field_id>hash_0700136027a919c7c7731fbe095b6f53ab127b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_003> + <item_004> + <data_input_field_id>hash_070013b5c23f246559df38662c255f4aa21d6b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_004> + <item_005> + <data_input_field_id>hash_0700131cc1493a6781af2c478fa4de971531cf</data_input_field_id> + <t_value></t_value> + <value></value> + </item_005> + <item_006> + <data_input_field_id>hash_070013f4facc5e2ca7ebee621f09bc6d9fc792</data_input_field_id> + <t_value></t_value> + <value></value> + </item_006> + <item_007> + <data_input_field_id>hash_070013acb449d1451e8a2a655c2c99d31142c7</data_input_field_id> + <t_value></t_value> + <value></value> + </item_007> + <item_008> + <data_input_field_id>hash_070013617cdc8a230615e59f06f361ef6e7728</data_input_field_id> + <t_value></t_value> + <value></value> + </item_008> + </data> + </hash_010013fa4d4fff334b60e9064e89082173fe34> + <hash_010013a63ddba34026d2c07d73c0ef2ae64b54> + <name>HAProxy Backend Traffic Stats</name> + <ds> + <t_name></t_name> + <name>|host_description| - HAProxy - |query_bePxName| Backend Traffic Stats</name> + <data_input_id>hash_030013bf566c869ac6443b0c75d1c32b5a350e</data_input_id> + <t_rra_id></t_rra_id> + <t_rrd_step></t_rrd_step> + <rrd_step>300</rrd_step> + <t_active></t_active> + <active>on</active> + <rra_items>hash_150013c21df5178e5c955013591239eb0afd46|hash_1500130d9c0af8b8acdc7807943937b3208e29|hash_1500136fc2d038fb42950138b0ce3e9874cc60|hash_150013e36f3adb9f152adfa5dc50fd2b23337e|hash_150013a4aa6f4de84eaa00008f88d3f5bd8520|hash_150013e73fb797d3ab2a9b97c3ec29e9690910</rra_items> + </ds> + <items> + <hash_0800136c0e4debeb9b084231d858faabd82f8f> + <t_data_source_name></t_data_source_name> + <data_source_name>BytesOut</data_source_name> + <t_rrd_minimum></t_rrd_minimum> + <rrd_minimum>0</rrd_minimum> + <t_rrd_maximum></t_rrd_maximum> + <rrd_maximum>10000000000</rrd_maximum> + <t_data_source_type_id></t_data_source_type_id> + <data_source_type_id>2</data_source_type_id> + <t_rrd_heartbeat></t_rrd_heartbeat> + <rrd_heartbeat>600</rrd_heartbeat> + <t_data_input_field_id></t_data_input_field_id> + <data_input_field_id>0</data_input_field_id> + </hash_0800136c0e4debeb9b084231d858faabd82f8f> + <hash_0800132f5283f17a7cde63137189d4d3ea7e4e> + <t_data_source_name></t_data_source_name> + <data_source_name>BytesIn</data_source_name> + <t_rrd_minimum></t_rrd_minimum> + <rrd_minimum>0</rrd_minimum> + <t_rrd_maximum></t_rrd_maximum> + <rrd_maximum>10000000000</rrd_maximum> + <t_data_source_type_id></t_data_source_type_id> + <data_source_type_id>2</data_source_type_id> + <t_rrd_heartbeat></t_rrd_heartbeat> + <rrd_heartbeat>600</rrd_heartbeat> + <t_data_input_field_id></t_data_input_field_id> + <data_input_field_id>0</data_input_field_id> + </hash_0800132f5283f17a7cde63137189d4d3ea7e4e> + </items> + <data> + <item_000> + <data_input_field_id>hash_070013c1f36ee60c3dc98945556d57f26e475b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_000> + <item_001> + <data_input_field_id>hash_070013e6deda7be0f391399c5130e7c4a48b28</data_input_field_id> + <t_value></t_value> + <value></value> + </item_001> + <item_002> + <data_input_field_id>hash_070013cbbe5c1ddfb264a6e5d509ce1c78c95f</data_input_field_id> + <t_value></t_value> + <value></value> + </item_002> + <item_003> + <data_input_field_id>hash_0700136027a919c7c7731fbe095b6f53ab127b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_003> + <item_004> + <data_input_field_id>hash_070013b5c23f246559df38662c255f4aa21d6b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_004> + <item_005> + <data_input_field_id>hash_0700131cc1493a6781af2c478fa4de971531cf</data_input_field_id> + <t_value></t_value> + <value></value> + </item_005> + <item_006> + <data_input_field_id>hash_070013f4facc5e2ca7ebee621f09bc6d9fc792</data_input_field_id> + <t_value></t_value> + <value></value> + </item_006> + <item_007> + <data_input_field_id>hash_070013acb449d1451e8a2a655c2c99d31142c7</data_input_field_id> + <t_value></t_value> + <value></value> + </item_007> + <item_008> + <data_input_field_id>hash_070013617cdc8a230615e59f06f361ef6e7728</data_input_field_id> + <t_value></t_value> + <value></value> + </item_008> + </data> + </hash_010013a63ddba34026d2c07d73c0ef2ae64b54> + <hash_150013c21df5178e5c955013591239eb0afd46> + <name>Daily (5 Minute Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>1</steps> + <rows>600</rows> + <timespan>86400</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_150013c21df5178e5c955013591239eb0afd46> + <hash_1500130d9c0af8b8acdc7807943937b3208e29> + <name>Weekly (30 Minute Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>6</steps> + <rows>700</rows> + <timespan>604800</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_1500130d9c0af8b8acdc7807943937b3208e29> + <hash_1500136fc2d038fb42950138b0ce3e9874cc60> + <name>Monthly (2 Hour Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>24</steps> + <rows>775</rows> + <timespan>2678400</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_1500136fc2d038fb42950138b0ce3e9874cc60> + <hash_150013e36f3adb9f152adfa5dc50fd2b23337e> + <name>Yearly (1 Day Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>288</steps> + <rows>797</rows> + <timespan>33053184</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_150013e36f3adb9f152adfa5dc50fd2b23337e> + <hash_1500130028a19ed71b758898eaa55ab1c59694> + <name>Three days (5 minutes average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>6</steps> + <rows>700</rows> + <timespan>302400</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_1500130028a19ed71b758898eaa55ab1c59694> + <hash_150013e73fb797d3ab2a9b97c3ec29e9690910> + <name>Hourly (1 Minute Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>1</steps> + <rows>500</rows> + <timespan>14400</timespan> + <cf_items>1|3</cf_items> + </hash_150013e73fb797d3ab2a9b97c3ec29e9690910> + <hash_060013e9c43831e54eca8069317a2ce8c6f751> + <name>Normal</name> + <gprint_text>%8.2lf %s</gprint_text> + </hash_060013e9c43831e54eca8069317a2ce8c6f751> +</cacti> diff --git a/admin/netsnmp-perl/cacti_data_query_haproxy_frontends.xml b/admin/netsnmp-perl/cacti_data_query_haproxy_frontends.xml new file mode 100644 index 0000000..1429b07 --- /dev/null +++ b/admin/netsnmp-perl/cacti_data_query_haproxy_frontends.xml @@ -0,0 +1,750 @@ +<cacti> + <hash_0400138cb70c1064bd60742726af23828c4b05> + <name>HAProxy Frontends</name> + <description></description> + <xml_path><path_cacti>/resource/snmp_queries/haproxy_frontend.xml</xml_path> + <data_input_id>hash_030013bf566c869ac6443b0c75d1c32b5a350e</data_input_id> + <graphs> + <hash_110013c1c2bca3af0ae4e2ce0de096aa79dba5> + <name>HAProxy Frontend Sessions</name> + <graph_template_id>hash_00001328b6727aa54dde6bb3f5dde939ae03aa</graph_template_id> + <rrd> + <item_000> + <snmp_field_name>feSTot</snmp_field_name> + <data_template_id>hash_0100139f985697a7530256b4e35c95ef03db20</data_template_id> + <data_template_rrd_id>hash_080013f9c76e05d0a87b2d32f9a5b014e17aab</data_template_rrd_id> + </item_000> + <item_001> + <snmp_field_name>feEReq</snmp_field_name> + <data_template_id>hash_0100139f985697a7530256b4e35c95ef03db20</data_template_id> + <data_template_rrd_id>hash_080013c137bec94d7220e65a5b3dfa4049c242</data_template_rrd_id> + </item_001> + </rrd> + <sv_graph> + <hash_1200130f0e4ffcd11f807d23794ab805d7901a> + <field_name>TotalSessions</field_name> + <sequence>1</sequence> + <text>TotalSessions</text> + </hash_1200130f0e4ffcd11f807d23794ab805d7901a> + <hash_1200134fc506db9ce45c0e5cb38a429ad8e077> + <field_name>RequestErrors</field_name> + <sequence>1</sequence> + <text>RequestErrors</text> + </hash_1200134fc506db9ce45c0e5cb38a429ad8e077> + </sv_graph> + <sv_data_source> + <hash_1300138a5efc51c95b400c3139b352ce110969> + <field_name>RequestErrors</field_name> + <data_template_id>hash_0100139f985697a7530256b4e35c95ef03db20</data_template_id> + <sequence>1</sequence> + <text>RequestErrors</text> + </hash_1300138a5efc51c95b400c3139b352ce110969> + <hash_130013e374903ab025bc2728f2f9abeb412ac3> + <field_name>TotalSessions</field_name> + <data_template_id>hash_0100139f985697a7530256b4e35c95ef03db20</data_template_id> + <sequence>1</sequence> + <text>TotalSessions</text> + </hash_130013e374903ab025bc2728f2f9abeb412ac3> + </sv_data_source> + </hash_110013c1c2bca3af0ae4e2ce0de096aa79dba5> + <hash_1100130838495d5d82f25f4a675ee7c56543a5> + <name>HAProxy Frontend Traffic</name> + <graph_template_id>hash_000013d0fe9e9efc2746de488fdede0419b051</graph_template_id> + <rrd> + <item_000> + <snmp_field_name>feBOut</snmp_field_name> + <data_template_id>hash_010013a88327df77ea19e333ddd96096c34751</data_template_id> + <data_template_rrd_id>hash_0800137db81cd58fbbbd203af0f55c15c2081a</data_template_rrd_id> + </item_000> + <item_001> + <snmp_field_name>feBIn</snmp_field_name> + <data_template_id>hash_010013a88327df77ea19e333ddd96096c34751</data_template_id> + <data_template_rrd_id>hash_08001305772980bb6de1f12223d7ec53e323c4</data_template_rrd_id> + </item_001> + </rrd> + <sv_graph> + <hash_120013934d1311136bccb4d9ca5a67e240afeb> + <field_name>BytesIn</field_name> + <sequence>1</sequence> + <text>BytesIn</text> + </hash_120013934d1311136bccb4d9ca5a67e240afeb> + <hash_12001399a6e6fb09b025bc60a214cb00e6d1f0> + <field_name>BytesOut</field_name> + <sequence>1</sequence> + <text>BytesOut</text> + </hash_12001399a6e6fb09b025bc60a214cb00e6d1f0> + </sv_graph> + <sv_data_source> + <hash_1300135f35cdaeda1a1169be21e52a85af339e> + <field_name>BytesOut</field_name> + <data_template_id>hash_0100139f985697a7530256b4e35c95ef03db20</data_template_id> + <sequence>1</sequence> + <text>BytesOut</text> + </hash_1300135f35cdaeda1a1169be21e52a85af339e> + <hash_1300136ee916a0c0ce8dad133b9dfcf32e2581> + <field_name>BytesIn</field_name> + <data_template_id>hash_0100139f985697a7530256b4e35c95ef03db20</data_template_id> + <sequence>1</sequence> + <text>BytesIn</text> + </hash_1300136ee916a0c0ce8dad133b9dfcf32e2581> + <hash_13001382c5a3b953f8d1583b168d15beed6e9c> + <field_name>BytesOut</field_name> + <data_template_id>hash_010013a88327df77ea19e333ddd96096c34751</data_template_id> + <sequence>1</sequence> + <text>BytesOut</text> + </hash_13001382c5a3b953f8d1583b168d15beed6e9c> + <hash_1300132c486fa1a5e875179031ea9f5328614b> + <field_name>BytesIn</field_name> + <data_template_id>hash_010013a88327df77ea19e333ddd96096c34751</data_template_id> + <sequence>1</sequence> + <text>BytesIn</text> + </hash_1300132c486fa1a5e875179031ea9f5328614b> + </sv_data_source> + </hash_1100130838495d5d82f25f4a675ee7c56543a5> + </graphs> + </hash_0400138cb70c1064bd60742726af23828c4b05> + <hash_030013bf566c869ac6443b0c75d1c32b5a350e> + <name>Get SNMP Data (Indexed)</name> + <type_id>3</type_id> + <input_string></input_string> + <fields> + <hash_070013617cdc8a230615e59f06f361ef6e7728> + <name>SNMP IP Address</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>hostname</type_code> + <input_output>in</input_output> + <data_name>management_ip</data_name> + </hash_070013617cdc8a230615e59f06f361ef6e7728> + <hash_070013acb449d1451e8a2a655c2c99d31142c7> + <name>SNMP Community</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>snmp_community</type_code> + <input_output>in</input_output> + <data_name>snmp_community</data_name> + </hash_070013acb449d1451e8a2a655c2c99d31142c7> + <hash_070013f4facc5e2ca7ebee621f09bc6d9fc792> + <name>SNMP Username (v3)</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls>on</allow_nulls> + <type_code>snmp_username</type_code> + <input_output>in</input_output> + <data_name>snmp_username</data_name> + </hash_070013f4facc5e2ca7ebee621f09bc6d9fc792> + <hash_0700131cc1493a6781af2c478fa4de971531cf> + <name>SNMP Password (v3)</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls>on</allow_nulls> + <type_code>snmp_password</type_code> + <input_output>in</input_output> + <data_name>snmp_password</data_name> + </hash_0700131cc1493a6781af2c478fa4de971531cf> + <hash_070013b5c23f246559df38662c255f4aa21d6b> + <name>SNMP Version (1, 2, or 3)</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>snmp_version</type_code> + <input_output>in</input_output> + <data_name>snmp_version</data_name> + </hash_070013b5c23f246559df38662c255f4aa21d6b> + <hash_0700136027a919c7c7731fbe095b6f53ab127b> + <name>Index Type</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>index_type</type_code> + <input_output>in</input_output> + <data_name>index_type</data_name> + </hash_0700136027a919c7c7731fbe095b6f53ab127b> + <hash_070013cbbe5c1ddfb264a6e5d509ce1c78c95f> + <name>Index Value</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>index_value</type_code> + <input_output>in</input_output> + <data_name>index_value</data_name> + </hash_070013cbbe5c1ddfb264a6e5d509ce1c78c95f> + <hash_070013e6deda7be0f391399c5130e7c4a48b28> + <name>Output Type ID</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>output_type</type_code> + <input_output>in</input_output> + <data_name>output_type</data_name> + </hash_070013e6deda7be0f391399c5130e7c4a48b28> + <hash_070013c1f36ee60c3dc98945556d57f26e475b> + <name>SNMP Port</name> + <update_rra></update_rra> + <regexp_match></regexp_match> + <allow_nulls></allow_nulls> + <type_code>snmp_port</type_code> + <input_output>in</input_output> + <data_name>snmp_port</data_name> + </hash_070013c1f36ee60c3dc98945556d57f26e475b> + </fields> + </hash_030013bf566c869ac6443b0c75d1c32b5a350e> + <hash_00001328b6727aa54dde6bb3f5dde939ae03aa> + <name>HAProxy Frontend Sessions</name> + <graph> + <t_title></t_title> + <title>|host_description| - HaProxy - |query_fePxName| Frontend Sessions</title> + <t_image_format_id></t_image_format_id> + <image_format_id>1</image_format_id> + <t_height></t_height> + <height>120</height> + <t_width></t_width> + <width>500</width> + <t_auto_scale></t_auto_scale> + <auto_scale>on</auto_scale> + <t_auto_scale_opts></t_auto_scale_opts> + <auto_scale_opts>2</auto_scale_opts> + <t_auto_scale_log></t_auto_scale_log> + <auto_scale_log></auto_scale_log> + <t_auto_scale_rigid></t_auto_scale_rigid> + <auto_scale_rigid></auto_scale_rigid> + <t_auto_padding></t_auto_padding> + <auto_padding>on</auto_padding> + <t_export></t_export> + <export>on</export> + <t_upper_limit></t_upper_limit> + <upper_limit>10000</upper_limit> + <t_lower_limit></t_lower_limit> + <lower_limit>0</lower_limit> + <t_base_value></t_base_value> + <base_value>1000</base_value> + <t_unit_value></t_unit_value> + <unit_value></unit_value> + <t_unit_exponent_value></t_unit_exponent_value> + <unit_exponent_value></unit_exponent_value> + <t_vertical_label></t_vertical_label> + <vertical_label></vertical_label> + </graph> + <items> + <hash_100013b1ecfd75df9c17c0ba11acc5e9b7d8f8> + <task_item_id>hash_080013f9c76e05d0a87b2d32f9a5b014e17aab</task_item_id> + <color_id>0000FF</color_id> + <graph_type_id>5</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Total Sessions:</text_format> + <hard_return></hard_return> + <sequence>5</sequence> + </hash_100013b1ecfd75df9c17c0ba11acc5e9b7d8f8> + <hash_100013fa878148199aee5bb2a10b7693318347> + <task_item_id>hash_080013f9c76e05d0a87b2d32f9a5b014e17aab</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>4</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Current:</text_format> + <hard_return></hard_return> + <sequence>6</sequence> + </hash_100013fa878148199aee5bb2a10b7693318347> + <hash_1000137d834c383afa4863974edc19a337e260> + <task_item_id>hash_080013f9c76e05d0a87b2d32f9a5b014e17aab</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Average:</text_format> + <hard_return></hard_return> + <sequence>7</sequence> + </hash_1000137d834c383afa4863974edc19a337e260> + <hash_1000138b0422b293230883462cfbfe32144d47> + <task_item_id>hash_080013f9c76e05d0a87b2d32f9a5b014e17aab</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>3</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Maximum:</text_format> + <hard_return>on</hard_return> + <sequence>8</sequence> + </hash_1000138b0422b293230883462cfbfe32144d47> + <hash_1000131c87ed4e76c026cd131418d792822944> + <task_item_id>hash_080013c137bec94d7220e65a5b3dfa4049c242</task_item_id> + <color_id>EA8F00</color_id> + <graph_type_id>5</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Request Errors:</text_format> + <hard_return></hard_return> + <sequence>9</sequence> + </hash_1000131c87ed4e76c026cd131418d792822944> + <hash_100013a9993114514cb1abea4b929f984222ea> + <task_item_id>hash_080013c137bec94d7220e65a5b3dfa4049c242</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>4</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Current:</text_format> + <hard_return></hard_return> + <sequence>10</sequence> + </hash_100013a9993114514cb1abea4b929f984222ea> + <hash_1000131bc67adbaa8b77cd6c73d9622c7eebc1> + <task_item_id>hash_080013c137bec94d7220e65a5b3dfa4049c242</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Average:</text_format> + <hard_return></hard_return> + <sequence>12</sequence> + </hash_1000131bc67adbaa8b77cd6c73d9622c7eebc1> + <hash_1000138840d17711368b90a61132ba83e9edb8> + <task_item_id>hash_080013c137bec94d7220e65a5b3dfa4049c242</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>3</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Maximum:</text_format> + <hard_return>on</hard_return> + <sequence>13</sequence> + </hash_1000138840d17711368b90a61132ba83e9edb8> + <hash_100013e8ddbe92933ba99b2d2ebc8f76a06e2e> + <task_item_id>0</task_item_id> + <color_id>0</color_id> + <graph_type_id>1</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Graph Last Updated: |date_time|</text_format> + <hard_return>on</hard_return> + <sequence>14</sequence> + </hash_100013e8ddbe92933ba99b2d2ebc8f76a06e2e> + </items> + <inputs> + <hash_0900134bedc49c15c9557fc95cdbc8850a5cb1> + <name>Data Source [TotalSessions]</name> + <description></description> + <column_name>task_item_id</column_name> + <items>hash_000013b1ecfd75df9c17c0ba11acc5e9b7d8f8|hash_000013fa878148199aee5bb2a10b7693318347|hash_0000138b0422b293230883462cfbfe32144d47|hash_0000137d834c383afa4863974edc19a337e260</items> + </hash_0900134bedc49c15c9557fc95cdbc8850a5cb1> + <hash_090013f3f3dfd39bb035006de08df94415e828> + <name>Data Source [RequestErrors]</name> + <description></description> + <column_name>task_item_id</column_name> + <items>hash_0000131c87ed4e76c026cd131418d792822944|hash_000013a9993114514cb1abea4b929f984222ea|hash_0000131bc67adbaa8b77cd6c73d9622c7eebc1|hash_0000138840d17711368b90a61132ba83e9edb8</items> + </hash_090013f3f3dfd39bb035006de08df94415e828> + </inputs> + </hash_00001328b6727aa54dde6bb3f5dde939ae03aa> + <hash_000013d0fe9e9efc2746de488fdede0419b051> + <name>HAProxy Frontend Traffic</name> + <graph> + <t_title></t_title> + <title>|host_description| - HaProxy |query_fePxName| Frontend Traffic</title> + <t_image_format_id></t_image_format_id> + <image_format_id>1</image_format_id> + <t_height></t_height> + <height>120</height> + <t_width></t_width> + <width>500</width> + <t_auto_scale></t_auto_scale> + <auto_scale>on</auto_scale> + <t_auto_scale_opts></t_auto_scale_opts> + <auto_scale_opts>2</auto_scale_opts> + <t_auto_scale_log></t_auto_scale_log> + <auto_scale_log></auto_scale_log> + <t_auto_scale_rigid></t_auto_scale_rigid> + <auto_scale_rigid></auto_scale_rigid> + <t_auto_padding></t_auto_padding> + <auto_padding>on</auto_padding> + <t_export></t_export> + <export>on</export> + <t_upper_limit></t_upper_limit> + <upper_limit>10000000000</upper_limit> + <t_lower_limit></t_lower_limit> + <lower_limit>0</lower_limit> + <t_base_value></t_base_value> + <base_value>1024</base_value> + <t_unit_value></t_unit_value> + <unit_value></unit_value> + <t_unit_exponent_value></t_unit_exponent_value> + <unit_exponent_value></unit_exponent_value> + <t_vertical_label></t_vertical_label> + <vertical_label>bytes</vertical_label> + </graph> + <items> + <hash_100013d5c13ff711cbd645e9f88697b2c5e61b> + <task_item_id>hash_08001305772980bb6de1f12223d7ec53e323c4</task_item_id> + <color_id>6EA100</color_id> + <graph_type_id>5</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Ingress Traffic:</text_format> + <hard_return></hard_return> + <sequence>2</sequence> + </hash_100013d5c13ff711cbd645e9f88697b2c5e61b> + <hash_10001353cff0cd64c4d70574ef9da42f62c86a> + <task_item_id>hash_08001305772980bb6de1f12223d7ec53e323c4</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>4</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Current:</text_format> + <hard_return></hard_return> + <sequence>3</sequence> + </hash_10001353cff0cd64c4d70574ef9da42f62c86a> + <hash_1000136788d44f6207ce323ad40ccc8f15d462> + <task_item_id>hash_08001305772980bb6de1f12223d7ec53e323c4</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Average:</text_format> + <hard_return></hard_return> + <sequence>4</sequence> + </hash_1000136788d44f6207ce323ad40ccc8f15d462> + <hash_100013d4cb02a8fb7fa37ef1e37d8b78333ea3> + <task_item_id>hash_08001305772980bb6de1f12223d7ec53e323c4</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>3</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Maximum:</text_format> + <hard_return>on</hard_return> + <sequence>5</sequence> + </hash_100013d4cb02a8fb7fa37ef1e37d8b78333ea3> + <hash_1000137d82a7f3c82c698fe4e9cecc03d680b1> + <task_item_id>hash_0800137db81cd58fbbbd203af0f55c15c2081a</task_item_id> + <color_id>FF0000</color_id> + <graph_type_id>5</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Egress Traffic:</text_format> + <hard_return></hard_return> + <sequence>6</sequence> + </hash_1000137d82a7f3c82c698fe4e9cecc03d680b1> + <hash_100013d2d059378b521327426b451324bbb608> + <task_item_id>hash_0800137db81cd58fbbbd203af0f55c15c2081a</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>4</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Current:</text_format> + <hard_return></hard_return> + <sequence>7</sequence> + </hash_100013d2d059378b521327426b451324bbb608> + <hash_1000132eef0fae129ef21ad2d73e5e80814a23> + <task_item_id>hash_0800137db81cd58fbbbd203af0f55c15c2081a</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Average:</text_format> + <hard_return></hard_return> + <sequence>8</sequence> + </hash_1000132eef0fae129ef21ad2d73e5e80814a23> + <hash_1000138365462951b1f4e6b1a76f20b91be65d> + <task_item_id>hash_0800137db81cd58fbbbd203af0f55c15c2081a</task_item_id> + <color_id>0</color_id> + <graph_type_id>9</graph_type_id> + <consolidation_function_id>3</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Maximum:</text_format> + <hard_return>on</hard_return> + <sequence>9</sequence> + </hash_1000138365462951b1f4e6b1a76f20b91be65d> + <hash_100013eefc9c0f83c57d6d6f8d75fbd45965a3> + <task_item_id>0</task_item_id> + <color_id>0</color_id> + <graph_type_id>1</graph_type_id> + <consolidation_function_id>1</consolidation_function_id> + <cdef_id>0</cdef_id> + <value></value> + <gprint_id>hash_060013e9c43831e54eca8069317a2ce8c6f751</gprint_id> + <text_format>Graph Last Updated: |date_time|</text_format> + <hard_return>on</hard_return> + <sequence>10</sequence> + </hash_100013eefc9c0f83c57d6d6f8d75fbd45965a3> + </items> + <inputs> + <hash_090013384e7b730bb32653e3fbce5ce509977d> + <name>Data Source [BytesOut]</name> + <description></description> + <column_name>task_item_id</column_name> + <items>hash_000013d2d059378b521327426b451324bbb608|hash_0000137d82a7f3c82c698fe4e9cecc03d680b1|hash_0000132eef0fae129ef21ad2d73e5e80814a23|hash_0000138365462951b1f4e6b1a76f20b91be65d</items> + </hash_090013384e7b730bb32653e3fbce5ce509977d> + <hash_090013e5ff60e3069b2d28d905f6affa63250e> + <name>Data Source [BytesIn]</name> + <description></description> + <column_name>task_item_id</column_name> + <items>hash_00001353cff0cd64c4d70574ef9da42f62c86a|hash_000013d5c13ff711cbd645e9f88697b2c5e61b|hash_0000136788d44f6207ce323ad40ccc8f15d462|hash_000013d4cb02a8fb7fa37ef1e37d8b78333ea3</items> + </hash_090013e5ff60e3069b2d28d905f6affa63250e> + </inputs> + </hash_000013d0fe9e9efc2746de488fdede0419b051> + <hash_0100139f985697a7530256b4e35c95ef03db20> + <name>HAProxy Frontend Session Stats</name> + <ds> + <t_name></t_name> + <name>|host_description| - HAProxy - |query_fePxName| Frontend Session Stats</name> + <data_input_id>hash_030013bf566c869ac6443b0c75d1c32b5a350e</data_input_id> + <t_rra_id></t_rra_id> + <t_rrd_step></t_rrd_step> + <rrd_step>300</rrd_step> + <t_active></t_active> + <active>on</active> + <rra_items>hash_150013c21df5178e5c955013591239eb0afd46|hash_1500130d9c0af8b8acdc7807943937b3208e29|hash_1500136fc2d038fb42950138b0ce3e9874cc60|hash_150013e36f3adb9f152adfa5dc50fd2b23337e|hash_1500139b529013942d5a6891d05a84d17175e0|hash_150013e73fb797d3ab2a9b97c3ec29e9690910</rra_items> + </ds> + <items> + <hash_080013c137bec94d7220e65a5b3dfa4049c242> + <t_data_source_name></t_data_source_name> + <data_source_name>RequestErrors</data_source_name> + <t_rrd_minimum></t_rrd_minimum> + <rrd_minimum>0</rrd_minimum> + <t_rrd_maximum></t_rrd_maximum> + <rrd_maximum>10000</rrd_maximum> + <t_data_source_type_id></t_data_source_type_id> + <data_source_type_id>2</data_source_type_id> + <t_rrd_heartbeat></t_rrd_heartbeat> + <rrd_heartbeat>600</rrd_heartbeat> + <t_data_input_field_id></t_data_input_field_id> + <data_input_field_id>0</data_input_field_id> + </hash_080013c137bec94d7220e65a5b3dfa4049c242> + <hash_080013f9c76e05d0a87b2d32f9a5b014e17aab> + <t_data_source_name></t_data_source_name> + <data_source_name>TotalSessions</data_source_name> + <t_rrd_minimum></t_rrd_minimum> + <rrd_minimum>0</rrd_minimum> + <t_rrd_maximum></t_rrd_maximum> + <rrd_maximum>10000</rrd_maximum> + <t_data_source_type_id></t_data_source_type_id> + <data_source_type_id>2</data_source_type_id> + <t_rrd_heartbeat></t_rrd_heartbeat> + <rrd_heartbeat>600</rrd_heartbeat> + <t_data_input_field_id></t_data_input_field_id> + <data_input_field_id>0</data_input_field_id> + </hash_080013f9c76e05d0a87b2d32f9a5b014e17aab> + </items> + <data> + <item_000> + <data_input_field_id>hash_070013c1f36ee60c3dc98945556d57f26e475b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_000> + <item_001> + <data_input_field_id>hash_070013e6deda7be0f391399c5130e7c4a48b28</data_input_field_id> + <t_value></t_value> + <value></value> + </item_001> + <item_002> + <data_input_field_id>hash_070013cbbe5c1ddfb264a6e5d509ce1c78c95f</data_input_field_id> + <t_value></t_value> + <value></value> + </item_002> + <item_003> + <data_input_field_id>hash_0700136027a919c7c7731fbe095b6f53ab127b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_003> + <item_004> + <data_input_field_id>hash_070013b5c23f246559df38662c255f4aa21d6b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_004> + <item_005> + <data_input_field_id>hash_0700131cc1493a6781af2c478fa4de971531cf</data_input_field_id> + <t_value></t_value> + <value></value> + </item_005> + <item_006> + <data_input_field_id>hash_070013f4facc5e2ca7ebee621f09bc6d9fc792</data_input_field_id> + <t_value></t_value> + <value></value> + </item_006> + <item_007> + <data_input_field_id>hash_070013acb449d1451e8a2a655c2c99d31142c7</data_input_field_id> + <t_value></t_value> + <value></value> + </item_007> + <item_008> + <data_input_field_id>hash_070013617cdc8a230615e59f06f361ef6e7728</data_input_field_id> + <t_value></t_value> + <value></value> + </item_008> + </data> + </hash_0100139f985697a7530256b4e35c95ef03db20> + <hash_010013a88327df77ea19e333ddd96096c34751> + <name>HAProxy Frontend Traffic Stats</name> + <ds> + <t_name></t_name> + <name>|host_description| - HAProxy - |query_fePxName| Frontend Traffic Stats</name> + <data_input_id>hash_030013bf566c869ac6443b0c75d1c32b5a350e</data_input_id> + <t_rra_id></t_rra_id> + <t_rrd_step></t_rrd_step> + <rrd_step>300</rrd_step> + <t_active></t_active> + <active>on</active> + <rra_items>hash_150013c21df5178e5c955013591239eb0afd46|hash_1500130d9c0af8b8acdc7807943937b3208e29|hash_1500136fc2d038fb42950138b0ce3e9874cc60|hash_150013e36f3adb9f152adfa5dc50fd2b23337e|hash_15001369b0abdb84cea4d93762fd5a5d0c2777|hash_150013e73fb797d3ab2a9b97c3ec29e9690910</rra_items> + </ds> + <items> + <hash_0800137db81cd58fbbbd203af0f55c15c2081a> + <t_data_source_name></t_data_source_name> + <data_source_name>BytesOut</data_source_name> + <t_rrd_minimum></t_rrd_minimum> + <rrd_minimum>0</rrd_minimum> + <t_rrd_maximum></t_rrd_maximum> + <rrd_maximum>10000000000</rrd_maximum> + <t_data_source_type_id></t_data_source_type_id> + <data_source_type_id>2</data_source_type_id> + <t_rrd_heartbeat></t_rrd_heartbeat> + <rrd_heartbeat>600</rrd_heartbeat> + <t_data_input_field_id></t_data_input_field_id> + <data_input_field_id>0</data_input_field_id> + </hash_0800137db81cd58fbbbd203af0f55c15c2081a> + <hash_08001305772980bb6de1f12223d7ec53e323c4> + <t_data_source_name></t_data_source_name> + <data_source_name>BytesIn</data_source_name> + <t_rrd_minimum></t_rrd_minimum> + <rrd_minimum>0</rrd_minimum> + <t_rrd_maximum></t_rrd_maximum> + <rrd_maximum>10000000000</rrd_maximum> + <t_data_source_type_id></t_data_source_type_id> + <data_source_type_id>2</data_source_type_id> + <t_rrd_heartbeat></t_rrd_heartbeat> + <rrd_heartbeat>600</rrd_heartbeat> + <t_data_input_field_id></t_data_input_field_id> + <data_input_field_id>0</data_input_field_id> + </hash_08001305772980bb6de1f12223d7ec53e323c4> + </items> + <data> + <item_000> + <data_input_field_id>hash_070013c1f36ee60c3dc98945556d57f26e475b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_000> + <item_001> + <data_input_field_id>hash_070013e6deda7be0f391399c5130e7c4a48b28</data_input_field_id> + <t_value></t_value> + <value></value> + </item_001> + <item_002> + <data_input_field_id>hash_070013cbbe5c1ddfb264a6e5d509ce1c78c95f</data_input_field_id> + <t_value></t_value> + <value></value> + </item_002> + <item_003> + <data_input_field_id>hash_0700136027a919c7c7731fbe095b6f53ab127b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_003> + <item_004> + <data_input_field_id>hash_070013b5c23f246559df38662c255f4aa21d6b</data_input_field_id> + <t_value></t_value> + <value></value> + </item_004> + <item_005> + <data_input_field_id>hash_0700131cc1493a6781af2c478fa4de971531cf</data_input_field_id> + <t_value></t_value> + <value></value> + </item_005> + <item_006> + <data_input_field_id>hash_070013f4facc5e2ca7ebee621f09bc6d9fc792</data_input_field_id> + <t_value></t_value> + <value></value> + </item_006> + <item_007> + <data_input_field_id>hash_070013acb449d1451e8a2a655c2c99d31142c7</data_input_field_id> + <t_value></t_value> + <value></value> + </item_007> + <item_008> + <data_input_field_id>hash_070013617cdc8a230615e59f06f361ef6e7728</data_input_field_id> + <t_value></t_value> + <value></value> + </item_008> + </data> + </hash_010013a88327df77ea19e333ddd96096c34751> + <hash_150013c21df5178e5c955013591239eb0afd46> + <name>Daily (5 Minute Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>1</steps> + <rows>600</rows> + <timespan>86400</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_150013c21df5178e5c955013591239eb0afd46> + <hash_1500130d9c0af8b8acdc7807943937b3208e29> + <name>Weekly (30 Minute Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>6</steps> + <rows>700</rows> + <timespan>604800</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_1500130d9c0af8b8acdc7807943937b3208e29> + <hash_1500136fc2d038fb42950138b0ce3e9874cc60> + <name>Monthly (2 Hour Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>24</steps> + <rows>775</rows> + <timespan>2678400</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_1500136fc2d038fb42950138b0ce3e9874cc60> + <hash_150013e36f3adb9f152adfa5dc50fd2b23337e> + <name>Yearly (1 Day Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>288</steps> + <rows>797</rows> + <timespan>33053184</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_150013e36f3adb9f152adfa5dc50fd2b23337e> + <hash_1500136399acb234c65ef56054d5a82b23bc20> + <name>Three days (5 minutes average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>6</steps> + <rows>700</rows> + <timespan>302400</timespan> + <cf_items>1|2|3|4</cf_items> + </hash_1500136399acb234c65ef56054d5a82b23bc20> + <hash_150013e73fb797d3ab2a9b97c3ec29e9690910> + <name>Hourly (1 Minute Average)</name> + <x_files_factor>0.5</x_files_factor> + <steps>1</steps> + <rows>500</rows> + <timespan>14400</timespan> + <cf_items>1|3</cf_items> + </hash_150013e73fb797d3ab2a9b97c3ec29e9690910> + <hash_060013e9c43831e54eca8069317a2ce8c6f751> + <name>Normal</name> + <gprint_text>%8.2lf %s</gprint_text> + </hash_060013e9c43831e54eca8069317a2ce8c6f751> +</cacti> diff --git a/admin/netsnmp-perl/haproxy.pl b/admin/netsnmp-perl/haproxy.pl new file mode 100644 index 0000000..64684ad --- /dev/null +++ b/admin/netsnmp-perl/haproxy.pl @@ -0,0 +1,249 @@ +# +# Net-SNMP perl plugin for HAProxy +# Version 0.30 +# +# Copyright 2007-2010 Krzysztof Piotr Oledzki <ole@ans.pl> +# +# 1. get a variable from "show stat": +# 1.3.6.1.4.1.29385.106.1.$type.$field.$iid.$sid +# type: 0->frontend, 1->backend, 2->server, 3->socket +# +# 2. get a variable from "show info": +# 1.3.6.1.4.1.29385.106.2.$req.$varnr +# +# TODO: +# - implement read timeout +# + +use NetSNMP::agent (':all'); +use NetSNMP::ASN qw(:all); +use IO::Socket::UNIX; + +use strict; + +my $agent = new NetSNMP::agent('Name' => 'HAProxy'); +my $sa = "/var/run/haproxy.stat"; + +use constant OID_HAPROXY => '1.3.6.1.4.1.29385.106'; +use constant OID_HAPROXY_STATS => OID_HAPROXY . '.1'; +use constant OID_HAPROXY_INFO => OID_HAPROXY . '.2'; + +my $oid_stat = new NetSNMP::OID(OID_HAPROXY_STATS); +my $oid_info = new NetSNMP::OID(OID_HAPROXY_INFO); + +use constant STATS_PXNAME => 0; +use constant STATS_SVNAME => 1; +use constant STATS_IID => 27; +use constant STATS_SID => 28; +use constant STATS_TYPE => 32; + +use constant FIELD_INDEX => 10001; +use constant FIELD_NAME => 10002; + +my %info_vars = ( + 0 => 'Name', + 1 => 'Version', + 2 => 'Release_date', + 3 => 'Nbproc', + 4 => 'Process_num', + 5 => 'Pid', + 6 => 'Uptime', + 7 => 'Uptime_sec', + 8 => 'Memmax_MB', + 9 => 'Ulimit-n', + 10 => 'Maxsock', + 11 => 'Maxconn', + 12 => 'Maxpipes', + 13 => 'CurrConns', + 14 => 'PipesUsed', + 15 => 'PipesFree', + 16 => 'Tasks', + 17 => 'Run_queue', + 18 => 'node', + 19 => 'description', +); + +sub find_next_stat_id { + my($type, $field, $proxyid, $sid) = @_; + + my $obj = 1 << $type; + + my $np = -1; + my $nl = -1; + + my $sock = new IO::Socket::UNIX (Peer => $sa, Type => SOCK_STREAM, Timeout => 1); + next if !$sock; + + print $sock "show stat -1 $obj -1\n"; + + while(<$sock>) { + chomp; + my @d = split(','); + + last if !$d[$field] && $field != FIELD_INDEX && $field != FIELD_NAME && /^#/; + next if /^#/; + + next if $d[STATS_TYPE] != $type; + + next if ($d[STATS_IID] < $proxyid) || ($d[STATS_IID] == $proxyid && $d[STATS_SID] <= $sid); + + if ($np == -1 || $d[STATS_IID] < $np || ($d[STATS_IID] == $np && $d[STATS_SID] < $nl)) { + $np = $d[STATS_IID]; + $nl = $d[STATS_SID]; + next; + } + } + + close($sock); + + return 0 if ($np == -1); + + return "$type.$field.$np.$nl" +} + +sub haproxy_stat { + my($handler, $registration_info, $request_info, $requests) = @_; + + for(my $request = $requests; $request; $request = $request->next()) { + my $oid = $request->getOID(); + + $oid =~ s/$oid_stat//; + $oid =~ s/^\.//; + + my $mode = $request_info->getMode(); + + my($type, $field, $proxyid, $sid, $or) = split('\.', $oid, 5); + + next if $type > 3 || defined($or); + + if ($mode == MODE_GETNEXT) { + + $type = 0 if !$type; + $field = 0 if !$field; + $proxyid = 0 if !$proxyid; + $sid = 0 if !$sid; + + my $nextid = find_next_stat_id($type, $field, $proxyid, $sid); + $nextid = find_next_stat_id($type, $field+1, 0, 0) if !$nextid; + $nextid = find_next_stat_id($type+1, 0, 0, 0) if !$nextid; + + if ($nextid) { + ($type, $field, $proxyid, $sid) = split('\.', $nextid); + $request->setOID(sprintf("%s.%s", OID_HAPROXY_STATS, $nextid)); + $mode = MODE_GET; + } + } + + if ($mode == MODE_GET) { + next if !defined($proxyid) || !defined($type) || !defined($sid) || !defined($field); + + my $obj = 1 << $type; + + my $sock = new IO::Socket::UNIX (Peer => $sa, Type => SOCK_STREAM, Timeout => 1); + next if !$sock; + + print $sock "show stat $proxyid $obj $sid\n"; + + while(<$sock>) { + chomp; + my @data = split(','); + + last if !defined($data[$field]) && $field != FIELD_INDEX && $field != FIELD_NAME; + + if ($proxyid) { + next if $data[STATS_IID] ne $proxyid; + next if $data[STATS_SID] ne $sid; + next if $data[STATS_TYPE] ne $type; + } + + if ($field == FIELD_INDEX) { + $request->setValue(ASN_OCTET_STR, + sprintf("%s.%s", $data[STATS_IID], + $data[STATS_SID])); + } elsif ($field == FIELD_NAME) { + $request->setValue(ASN_OCTET_STR, + sprintf("%s/%s", $data[STATS_PXNAME], + $data[STATS_SVNAME])); + } else { + $request->setValue(ASN_OCTET_STR, $data[$field]); + } + + close($sock); + last; + } + + close($sock); + next; + } + + } +} + +sub haproxy_info { + my($handler, $registration_info, $request_info, $requests) = @_; + + for(my $request = $requests; $request; $request = $request->next()) { + my $oid = $request->getOID(); + + $oid =~ s/$oid_info//; + $oid =~ s/^\.//; + + my $mode = $request_info->getMode(); + + my($req, $nr, $or) = split('\.', $oid, 3); + + next if $req >= 2 || defined($or); + + if ($mode == MODE_GETNEXT) { + $req = 0 if !defined($req); + $nr = -1 if !defined($nr); + + if (!defined($info_vars{$nr+1})) { + $req++; + $nr = -1; + } + + next if $req >= 2; + + $request->setOID(sprintf("%s.%s.%s", OID_HAPROXY_INFO, $req, ++$nr)); + $mode = MODE_GET; + + } + + if ($mode == MODE_GET) { + + next if !defined($req) || !defined($nr); + + if ($req == 0) { + next if !defined($info_vars{$nr}); + $request->setValue(ASN_OCTET_STR, $info_vars{$nr}); + next; + } + + if ($req == 1) { + next if !defined($info_vars{$nr}); + + my $sock = new IO::Socket::UNIX (Peer => $sa, Type => SOCK_STREAM, Timeout => 1); + next if !$sock; + + print $sock "show info\n"; + + while(<$sock>) { + chomp; + my ($key, $val) = /(.*):\s*(.*)/; + + next if $info_vars{$nr} ne $key; + + $request->setValue(ASN_OCTET_STR, $val); + last; + } + + close($sock); + } + } + } +} + +$agent->register('HAProxy stat', OID_HAPROXY_STATS, \&haproxy_stat); +$agent->register('HAProxy info', OID_HAPROXY_INFO, \&haproxy_info); + diff --git a/admin/netsnmp-perl/haproxy_backend.xml b/admin/netsnmp-perl/haproxy_backend.xml new file mode 100644 index 0000000..26ce63f --- /dev/null +++ b/admin/netsnmp-perl/haproxy_backend.xml @@ -0,0 +1,83 @@ +<interface> + <name>HAProxy - backend</name> + <oid_index>.1.3.6.1.4.1.29385.106.1.1.10001</oid_index> + <fields> + <beIID> + <name>Proxy ID</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.27</oid> + </beIID> + <beSID> + <name>Service ID</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.28</oid> + </beSID> + <bePxName> + <name>Proxy Name</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.0</oid> + </bePxName> + <beSvName> + <name>Service Name</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.1</oid> + </beSvName> + <beSTot> + <name>Total Sessions</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.7</oid> + </beSTot> + <beBIn> + <name>Bytes In</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.8</oid> + </beBIn> + <beBOut> + <name>Bytes Out</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.9</oid> + </beBOut> + <beEConn> + <name>Connection Errors</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.13</oid> + </beEConn> + <beEResp> + <name>Response Errors</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.14</oid> + </beEResp> + <beLBTot> + <name>LB Total</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.30</oid> + </beLBTot> + <beDReq> + <name>Denied Requests</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.1.10</oid> + </beDReq> + </fields> +</interface> diff --git a/admin/netsnmp-perl/haproxy_frontend.xml b/admin/netsnmp-perl/haproxy_frontend.xml new file mode 100644 index 0000000..ade2a77 --- /dev/null +++ b/admin/netsnmp-perl/haproxy_frontend.xml @@ -0,0 +1,83 @@ +<interface> + <name>HAProxy - frontend</name> + <oid_index>.1.3.6.1.4.1.29385.106.1.0.10001</oid_index> + <fields> + <feIID> + <name>Proxy ID</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.27</oid> + </feIID> + <feSID> + <name>Service ID</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.28</oid> + </feSID> + <fePxName> + <name>Proxy Name</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.0</oid> + </fePxName> + <feSvName> + <name>Service Name</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.1</oid> + </feSvName> + <feSCur> + <name>Current Sessions</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.4</oid> + </feSCur> + <feSMax> + <name>Maximum Sessions</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.5</oid> + </feSMax> + <feSTot> + <name>Total Sessions</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.7</oid> + </feSTot> + <feEReq> + <name>Request Errors</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.12</oid> + </feEReq> + <feBIn> + <name>Bytes In</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.8</oid> + </feBIn> + <feBOut> + <name>Bytes Out</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.9</oid> + </feBOut> + <feDReq> + <name>Denied Requests</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.0.10</oid> + </feDReq> + </fields> +</interface> diff --git a/admin/netsnmp-perl/haproxy_socket.xml b/admin/netsnmp-perl/haproxy_socket.xml new file mode 100644 index 0000000..63ae110 --- /dev/null +++ b/admin/netsnmp-perl/haproxy_socket.xml @@ -0,0 +1,90 @@ +<interface> + <name>HAProxy - socket</name> + <oid_index>.1.3.6.1.4.1.29385.106.1.3.10001</oid_index> + <fields> + <feseID> + <name>Unique Index</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.10001</oid> + </feseID> + <feIID> + <name>Proxy ID</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.27</oid> + </feIID> + <feSID> + <name>Service ID</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.28</oid> + </feSID> + <fePxName> + <name>Proxy Name</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.0</oid> + </fePxName> + <feSvName> + <name>Service Name</name> + <method>get</method> + <source>value</source> + <direction>input</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.1</oid> + </feSvName> + <feSCur> + <name>Current Sessions</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.4</oid> + </feSCur> + <feSMax> + <name>Maximum Sessions</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.5</oid> + </feSMax> + <feSTot> + <name>Total Sessions</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.7</oid> + </feSTot> + <feEReq> + <name>Request Errors</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.12</oid> + </feEReq> + <feBIn> + <name>Bytes In</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.8</oid> + </feBIn> + <feBOut> + <name>Bytes Out</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.9</oid> + </feBOut> + <feDReq> + <name>Denied Requests</name> + <method>get</method> + <source>value</source> + <direction>output</direction> + <oid>.1.3.6.1.4.1.29385.106.1.3.10</oid> + </feDReq> + </fields> +</interface> diff --git a/admin/release-estimator/README.md b/admin/release-estimator/README.md new file mode 100644 index 0000000..a51f731 --- /dev/null +++ b/admin/release-estimator/README.md @@ -0,0 +1,68 @@ +# Release Estimator +This tool monitors the HAProxy stable branches and calculates a proposed +release date for the next minor release based on the bug fixes that are in +the queue. + + +## Requirements + - Python 3.x + - [lxml](https://lxml.de/installation.html) + + +## Usage + release-estimator.py [-h] [--print] [--to-email TO_EMAIL] + [--from-email FROM_EMAIL] [--send-mail] + + optional arguments: + -h, --help show this help message and exit + --print Print email only + --to-email TO_EMAIL Send email to <email> + --from-email FROM_EMAIL + Send email from <email> + --send-mail Send email + + +## Examples + + +### Print only: + ./release-estimator.py --print + + +### Send email: + ./release-estimator.py --send-mail --from-email from@domain.local --to-email to@domain.local + + +## How it works +For each version we check the age and apply the following logic: + - Skip the release if it's: + - older than MAX_VERSION_AGE + - older than MAX_VERSION_AGE_NONLTS days and an odd numbered release + (1.9,2.1,2.3) + + - For all other valid releases we will then collect the number of bug fixes + in queue for each of the defined severity levels: + - BUG + - BUILD + - MINOR + - MEDIUM + - MAJOR + - CRITICAL + + We'll then begin calculating the proposed release date based on the last + release date plus the first commit date of the first bug fix for the defined + severity level. + + By default the proposed release dates use the following padding: + (Can be modified in THRESHOLDS) + - BUG/BUILD/MINOR - 28 days + - MEDIUM - 30 days + - MAJOR - 14 days + - CRITICAL - 2 days + + After we have a proposed release date we will assign a release urgency + to it. As we get closer to the proposed release date the urgency level changes. + By default the urgency levels and their times are: + - WARNING - proposed date is 7 days or less + - NOTICE - proposed date is 21 days or less + - INFO - proposed date is longer than the above diff --git a/admin/release-estimator/release-estimator.py b/admin/release-estimator/release-estimator.py new file mode 100755 index 0000000..bf005df --- /dev/null +++ b/admin/release-estimator/release-estimator.py @@ -0,0 +1,429 @@ +#!/usr/bin/python3 +# +# Release estimator for HAProxy +# +# A tool that monitors the HAProxy stable branches and calculates a proposed +# release date for the next minor release based on the bug fixes that are in +# the queue. +# +# Copyright 2020 HAProxy Technologies, Daniel Corbett <dcorbett@haproxy.com> +# +# This program 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 of the License, or (at your option) any later version. +# +# + +from lxml import html +import requests +import traceback +import smtplib +import math +import copy +import time +import sys +import argparse +from datetime import datetime +from datetime import timedelta +from email.mime.text import MIMEText + +# Do not report on versions older than +# MAX_VERSION_AGE. +MAX_VERSION_AGE = 1095 # days + +# Do not report on non-lts releases (odd releases) that +# are older than MAX_VERSION_AGE_NONLTS +MAX_VERSION_AGE_NONLTS = 547 # days + +# For each severity/issue type, set thresholds +# count - indicates how many bugs for this issue type should be in the queue +# time - indicates how many days should be added to the release date +THRESHOLDS = { + 'BUG' :{ 'count' : 1, 'time' : 28}, + 'BUILD' :{ 'count' : 1, 'time' : 28}, + 'MINOR' : { 'count' : 1, 'time' : 28}, + 'MEDIUM' : { 'count' : 1, 'time' : 30}, + 'MAJOR' : { 'count' : 1, 'time' : 14 }, + 'CRITICAL' : { 'count' : 1, 'time' : 2 } +} + +# Increase the urgency of a release as estimated time (in days) gets closer. +RELEASE_URGENCY = { 'WARNING' : 7, 'NOTICE' : 21, 'INFO' : '' } + +def search_set(s, f): + for t in s: + if f in t: + return True + +def check_for_email(s, parser): + if "@" not in s: + parser.print_help() + sys.exit() + +def main(): + global MAX_VERSION_AGE + global MAX_VERSION_AGE_NONLTS + global THRESHOLDS + global RELEASE_URGENCY + + SEND_MAIL=False + VERSIONS = [] + issues = {} + BUGQUEUE = {} + BUGS = { "bugs" :[] } + email_message = """Hi, + +This is a friendly bot that watches fixes pending for the next haproxy-stable release! One such e-mail is sent periodically once patches are waiting in the last maintenance branch, and an ideal release date is computed based on the severity of these fixes and their merge date. Responses to this mail must be sent to the mailing list. + +""" + + parser = argparse.ArgumentParser(description='HAProxy Stable Release Estimator') + parser.add_argument('--print', action="store_true", + help='Print email only') + parser.add_argument('--to-email', nargs=1, required=False, + help='Send email to <email>') + parser.add_argument('--from-email', nargs=1, required=False, + help='Send email from <email>') + parser.add_argument('--send-mail', action="store_true", + help='Send email') + args = parser.parse_args() + + if not args.print and not args.send_mail and not args.to_email and not args.from_email: + parser.print_help() + sys.exit() + + if args.send_mail and (not args.to_email or not args.from_email): + parser.print_help() + sys.exit() + + if args.to_email: + check_for_email(args.to_email[0], parser) + TO_EMAIL = args.to_email[0] + + if args.from_email: + check_for_email(args.from_email[0], parser) + FROM_EMAIL = args.from_email[0] + + if args.send_mail: + SEND_MAIL = True + + if SEND_MAIL: + try: + TO_EMAIL + FROM_EMAIL + except: + parser.print_help() + sys.exit() + + # + # Let's get the list of the current stable versions + # + + page = requests.get('http://www.haproxy.org/bugs/') + tree = html.fromstring(page.content) + + for x in (tree.xpath('//th')): + if x.xpath('./a/text()'): + VERSIONS.append(x.xpath('./a/text()')[0]) + + + # + # For each version let's check it's age. We'll apply the following logic: + # - Skip the release if it's: + # * older than MAX_VERSION_AGE days + # * older than MAX_VERSION_AGE_NONLTS days and an odd numbered release (1.9,2.1,2.3) + # + # For all other valid releases we will then collect the number of bug fixes + # in queue for each of the defined severity levels: + # - BUG + # - BUILD + # - MINOR + # - MEDIUM + # - MAJOR + # - CRITICAL + # + # We'll then begin calculating the proposed release date based on the last + # release date plus the first commit date of the first bug fix for the defined + # severity level. + # + # By default the proposed release dates use the following padding: + # (Can be modified in THRESHOLDS) + # - BUG/BUILD/MINOR - 28 days + # - MEDIUM - 30 days + # - MAJOR - 14 days + # - CRITICAL - 2 days + # + # After we have a proposed release date we will assign a release urgency + # to it. As we get closer to the proposed release date the urgency level changes. + # By default the urgency levels and their times are: + # - WARNING - proposed date is 7 days or less + # - NOTICE - proposed date is 21 days or less + # - INFO - proposed date is longer than the above + # + + for version in VERSIONS: + BUGQUEUE[version] = { "total" : 0, "last": "" } + VERSION_THRESHOLDS = copy.deepcopy(THRESHOLDS) + print("Collecting information on %s" % (version)) + page = requests.get('http://www.haproxy.org/bugs/bugs-%s.html' % (version)) + tree = html.fromstring(page.content) + + issues[version] = {} + issues_count = {} + release_soon = False + num_to_word = { + 1 : 'one', + 2 : 'two', + 3 : 'three', + 4 : 'four', + 5 : 'five', + 6 : 'six', + 7 : 'seven', + 8 : 'eight', + 9 : 'nine', + 10 : 'ten', + 11 : 'eleven', + 12 : 'twelve', + 13 : 'thirteen', + } + + # parse out the CHANGELOG link + CHANGELOG = tree.xpath('//a[contains(@href,"CHANGELOG")]/@href')[0] + + last_version = tree.xpath('//td[contains(text(), "last")]/../td/a/text()')[0] + first_version = "%s.0" % (version) + + # Get CHANGELOG for release + changelog_page = requests.get(CHANGELOG) + try: + for l in changelog_page.content.decode('utf-8').split('\n'): + # the below is a bit of a hack to parse out valid years in the CHANGELOG + if (last_version in l) and ('201' in l or '202' in l or '200' in l) and '/' in l: + # set the date in which this version was last released + last_release_date = l.split(' ')[0] + last_release_datetime = datetime.strptime(last_release_date.strip(), '%Y/%m/%d') + BUGQUEUE[version]['last'] = last_release_date + break + for l in changelog_page.content.decode('utf-8').split('\n'): + # the below is a bit of a hack to parse out valid years in the CHANGELOG + if (first_version in l) and ('201' in l or '202' in l or '200' in l) and '/' in l: + # set the date in which this version was first released + first_release_date = l.split(' ')[0] + first_release_datetime = datetime.strptime(first_release_date.strip(), '%Y/%m/%d') + BUGQUEUE[version]['first'] = first_release_datetime + break + except: + print(traceback.format_exc()) + last_release_date = False + + # get unix timestamp for today and timestamp of first release date + today_ts = datetime.today().timestamp() + first_version_ts = BUGQUEUE[version]['first'].timestamp() + + # calculate the age of this version in days and years + version_age = math.ceil((today_ts-first_version_ts)/86400) + version_age_years = math.ceil(version_age/365) + + # We do not want to monitor versions that are older + # than MAX_VERSION_AGE or MAX_VERSION_AGE_NONLTS + if version_age >= MAX_VERSION_AGE: + print("\t - Version: %s is older than %d days, skipping" % (version, MAX_VERSION_AGE)) + continue + + if version_age > MAX_VERSION_AGE_NONLTS: + if int(version.split('.')[1]) % 2 > 0: + print("\t - Version: %s is not LTS and is older than %d days, skipping" % (version, MAX_VERSION_AGE_NONLTS)) + continue + + # If the release is older than 1 year let's increase the time until + # a release is due. <base time threshold> * <version age years> + if version_age_years > 1: + for k in VERSION_THRESHOLDS.keys(): + VERSION_THRESHOLDS[k]['time'] *= int(version_age_years) + + # Let's capture the bug table which contains each bug & their severity + bug_table = tree.xpath('//th[contains(text(), "Severity")]/ancestor::table[last()]')[0] + + # Loop through bug table and parse out the title of each bug + # found within the links and their merge date. + # Example is: 2020-10-19 BUG/MINOR: disable dynamic OCSP load with BoringSSL + for x in bug_table.xpath('.//a[contains(@href,"commitdiff")]'): + # Capture the bug label + # Example: BUG/MINOR: disable dynamic OCSP load with BoringSSL + issue_tmp = x.xpath('./text()')[0] + # Capture the date + # Example: 2020-10-19 + date_tmp = x.xpath('../preceding-sibling::td/text()')[0] + + # Split the bug into a severity + if "/" in issue_tmp: + bug_type = issue_tmp.split(':')[0].split('/')[1].strip() + else: + bug_type = issue_tmp.split(':')[0].strip() + bug_text = ":".join(issue_tmp.split(':')[1:]).strip() + if bug_type not in issues[version].keys(): + issues[version][bug_type] = set() + issues[version][bug_type].add("%s|%s" % (date_tmp, bug_text)) + + # Loop through the issue_types (severities) (MINOR, MEDIUM, MAJOR, etc.) + # We'll check if the severity has already been accounted for + # If not, we'll set the timestamp to the timestamp of the current issue + # If so, we'll check if the current bugs timestamp is less than the + # previous one. This will help us to determine when we first saw this + # severity type as calculations are based on the first time seeing a + # severity type. We'll then set the number of issues for each severity. + for issue_type in issues[version]: + issues_count[issue_type] = {} + for k in issues[version][issue_type]: + if 'timestamp' not in issues_count[issue_type].keys(): + issues_count[issue_type]['timestamp'] = int(time.mktime(datetime.strptime(k.split('|')[0], "%Y-%m-%d").timetuple())) + else: + if issues_count[issue_type]['timestamp'] > int(time.mktime(datetime.strptime(k.split('|')[0], "%Y-%m-%d").timetuple())): + issues_count[issue_type]['timestamp'] = int(time.mktime(datetime.strptime(k.split('|')[0], "%Y-%m-%d").timetuple())) + issues_count[issue_type]['count'] = len(issues[version][issue_type]) + + release_date = None + total_count = 0 + + # Let's check the count for each severity type and see if they + # are greater than our thresholds count. This can be used to + # hold off on calculating release estimates until a certain number of + # MINOR bugs have accumulated. + for issue_type in issues_count.keys(): + if issues_count[issue_type]['count'] >= VERSION_THRESHOLDS[issue_type]['count']: + # If the total number of issues is greater than the threshold + # for a severity we'll attempt to set a release date. + # We'll use the timestamp from the first time an issue was + # seen and add on the number of days specified within the + # THRESHOLDS for that issue type. We'll also increment + # the total number of issues that have been fixed in this + # version across all severities/issue types. + total_count += issues_count[issue_type]['count'] + issue_timestamp_delta = datetime.fromtimestamp(int(issues_count[issue_type]['timestamp'])) + timedelta(days=int(VERSION_THRESHOLDS[issue_type]['time'])) + if not release_date: release_date = issue_timestamp_delta + elif release_date > issue_timestamp_delta: release_date = issue_timestamp_delta + + if release_date: release_soon = True + if release_soon: + time_until_release = release_date - datetime.now() + + # If a release date has been sent, let's calculate how long + # in words until that release. i.e. "less than 2 weeks" + if release_soon: + for k in sorted(RELEASE_URGENCY.keys()): + if not RELEASE_URGENCY[k]: + release_urgency_msg = k + elif time_until_release.days <= RELEASE_URGENCY[k]: + release_urgency_msg = k + rounded_week_time = math.ceil(time_until_release.days/7.0) + if abs(rounded_week_time) > 1: + week_word = 'weeks' + else: + week_word = 'week' + try: + # We now have all of the required information for building + # the email message. + # TODO: Fix alignment + email_message = """%s + Last release %s was issued on %s. There are currently %d patches in the queue cut down this way: +""" % (email_message, last_version, last_release_datetime.strftime("%Y-%m-%d"), total_count) + for issue_type in sorted(issues_count.keys()): + email_message = "%s - %d %s, first one merged on %s\n" % (email_message, issues_count[issue_type]['count'],issue_type,datetime.fromtimestamp(int(issues_count[issue_type]['timestamp'])).strftime("%Y-%m-%d")) + email_message = "%s\nThus the computed ideal release date for %s would be %s, " % (email_message, ".".join(last_version.split(".")[:-1])+"."+str(int(last_version.split(".")[-1])+1), release_date.strftime("%Y-%m-%d")) + if rounded_week_time < 0: + email_message = "%swhich was %s %s ago.\n" % (email_message, num_to_word[abs(rounded_week_time)], week_word) + elif rounded_week_time == 0: + email_message = "%swhich was within the last week.\n" % (email_message) + else: + email_message = "%swhich is in %s %s or less.\n" % (email_message, num_to_word[rounded_week_time], week_word) + except Exception as err: + print(traceback.format_exc()) + sys.exit() + # Total number of bugs fixed in this version + # since last release. + BUGQUEUE[version]['total'] = total_count + + email_subject = "stable-bot: Bugfixes waiting for a release " + + # Add each version & their number of bugs to the subject + for k in sorted(BUGQUEUE.keys(), reverse=True): + if BUGQUEUE[k]['total'] > 0: + email_subject = "%s %s (%d)," % ( email_subject, k, BUGQUEUE[k]['total']) + + email_subject = email_subject.rstrip(",") + email_message = "%s\nThe current list of patches in the queue is:\n" % (email_message) + uniq_issues = set() + + # Parse out unique issues across all versions so that we can + # print them once with the list of affected versions. + for k in BUGQUEUE.keys(): + for issue_type in sorted(issues[k].keys()): + for issue in issues[k][issue_type]: + uniq_issues.add("%s|%s" % (issue_type,issue.split('|')[1])) + + # Loop through the unique issues and determine which versions + # are affected. + for i in uniq_issues: + affected_versions = [] + for k in BUGQUEUE.keys(): + try: + if search_set(issues[k][i.split('|')[0]], i.split('|')[1]): + affected_versions.append(k) + except Exception as e: + pass + if affected_versions: + affected_versions.sort() + try: + BUGS["bugs"].append({ "affected_versions" : affected_versions, "bug":i.split('|')[1], "severity":i.split('|')[0] }) + except: + BUGS["bugs"] = [ { "affected_versions" : affected_versions, "bug":i.split('|')[1], "severity":i.split('|')[0] } ] + + BUGS["bugs"] = sorted(BUGS["bugs"], key = lambda i: i['severity']) + + # Add each issue with affected versions to email message + # Example: + # - 1.8, 2.0, 2.1, 2.2 - MINOR : stats: fix validity of the json schema + for bug in BUGS["bugs"]: + email_message = "%s - %s %s %s : %s\n" % (email_message, ", ".join(bug["affected_versions"]).ljust(14), "-".rjust(12), bug["severity"].ljust(7), bug["bug"]) + + email_message="%s\n-- \nThe haproxy stable-bot is freely provided by HAProxy Technologies to help improve the quality of each HAProxy release. If you have any issue with these emails or if you want to suggest some improvements, please post them on the list so that the solutions suiting the most users can be found.\n" % (email_message) + + # If a message with actual issues exists let's either print it or send out + # an email. + if "first one merged on" in email_message: + if args.print: + print(email_subject) + print(email_message) + if SEND_MAIL: + print('Send email to:%s from:%s' % (TO_EMAIL, FROM_EMAIL), end="") + msg = MIMEText(email_message) + msg['to'] = TO_EMAIL + msg['from'] = FROM_EMAIL + msg['subject'] = email_subject + msg.add_header('reply-to', TO_EMAIL) + try: + server = smtplib.SMTP('127.0.0.1', timeout=10) + server.sendmail(msg['from'], [msg['to']], msg.as_string()) + print(" - Email sent") + except (ConnectionRefusedError, smtplib.SMTPConnectError): + print("- Error: SMTP Connection Error") + sys.exit() + except smtplib.SMTPServerDisconnected: + print('- Error: SMTP Server Disconnect (possible timeout)') + sys.exit() + except (smtplib.SMTPRecipientsRefused, smtplib.SMTPSenderRefused): + print('- Error: Recipients or Sender Refused') + sys.exit() + except (smtplib.SMTPHeloError, smtplib.SMTPAuthenticationError): + print('- Error: SMTP rejected HELO or requires Authentication') + sys.exit() + except: + print(traceback.format_exc()) + sys.exit() + + +if __name__ == "__main__": + main() + +sys.exit() diff --git a/admin/selinux/README b/admin/selinux/README new file mode 100644 index 0000000..7ad924d --- /dev/null +++ b/admin/selinux/README @@ -0,0 +1,18 @@ +This directory includes an selinux policy for haproxy. It assumes +the following file locations: + + /usr/sbin/haproxy -- binary + /etc/haproxy/haproxy\.cfg -- configuration + /var/run/haproxy\.pid -- pid-file + /var/run/haproxy\.sock(.*) -- stats socket + /var/empty/haproxy -- chroot dir + +To build and load it on RHEL5 you'll need the "selinux-policy-devel" package, +and from within this directory run: + + make -f /usr/share/selinux/devel/Makefile + sudo semodule -i haproxy.pp + restorecon /usr/sbin/haproxy /etc/haproxy/haproxy.cfg /var/run/haproxy.pid /var/run/haproxy.sock* + + +Feedback to Jan-Frode Myklebust <janfrode@tanso.no> is much appreciated, diff --git a/admin/selinux/haproxy.fc b/admin/selinux/haproxy.fc new file mode 100644 index 0000000..63a0828 --- /dev/null +++ b/admin/selinux/haproxy.fc @@ -0,0 +1,6 @@ +# haproxy labeling policy +# file: haproxy.fc +/usr/sbin/haproxy -- gen_context(system_u:object_r:haproxy_exec_t, s0) +/etc/haproxy/haproxy\.cfg -- gen_context(system_u:object_r:haproxy_conf_t, s0) +/var/run/haproxy\.pid -- gen_context(system_u:object_r:haproxy_var_run_t, s0) +/var/run/haproxy\.sock(.*) -- gen_context(system_u:object_r:haproxy_var_run_t, s0) diff --git a/admin/selinux/haproxy.if b/admin/selinux/haproxy.if new file mode 100644 index 0000000..236ad38 --- /dev/null +++ b/admin/selinux/haproxy.if @@ -0,0 +1,2 @@ +## <summary>selinux policy module for haproxy</summary> + diff --git a/admin/selinux/haproxy.te b/admin/selinux/haproxy.te new file mode 100644 index 0000000..bc124fb --- /dev/null +++ b/admin/selinux/haproxy.te @@ -0,0 +1,66 @@ +policy_module(haproxy,1.0.0) + +######################################## +# +# Declarations +# + +type haproxy_t; +type haproxy_exec_t; +type haproxy_port_t; +init_daemon_domain(haproxy_t, haproxy_exec_t) + +type haproxy_var_run_t; +files_pid_file(haproxy_var_run_t) + +type haproxy_conf_t; +files_config_file(haproxy_conf_t) + +######################################## +# +# Local policy +# + +# Configuration files - read +allow haproxy_t haproxy_conf_t : dir list_dir_perms; +allow haproxy_t haproxy_conf_t : file read_file_perms; +allow haproxy_t haproxy_conf_t : lnk_file read_file_perms; + +# PID and socket file - create, read, and write +files_pid_filetrans(haproxy_t, haproxy_var_run_t, { file sock_file }) +allow haproxy_t haproxy_var_run_t:file manage_file_perms; +allow haproxy_t haproxy_var_run_t:sock_file { create rename link setattr unlink }; + +allow haproxy_t self : tcp_socket create_stream_socket_perms; +allow haproxy_t self: udp_socket create_socket_perms; +allow haproxy_t self: capability { setgid setuid sys_chroot sys_resource kill }; +allow haproxy_t self: process { setrlimit signal }; + + +logging_send_syslog_msg(haproxy_t) + +corenet_tcp_bind_all_ports(haproxy_t) +corenet_tcp_connect_all_ports(haproxy_t) +corenet_tcp_bind_all_nodes(haproxy_t) +corenet_tcp_sendrecv_all_ports(haproxy_t) +corenet_tcp_recvfrom_unlabeled(haproxy_t) + +# use shared libraries +libs_use_ld_so(haproxy_t) +libs_use_shared_libs(haproxy_t) + +# Read /etc/localtime: +miscfiles_read_localization(haproxy_t) +# Read /etc/passwd and more. +files_read_etc_files(haproxy_t) + +# RHEL5 specific: +require { + type unlabeled_t; + type haproxy_t; + class packet send; + class packet recv; +} + +allow haproxy_t unlabeled_t:packet { send recv }; + diff --git a/admin/syntax-highlight/haproxy.vim b/admin/syntax-highlight/haproxy.vim new file mode 100644 index 0000000..f559df0 --- /dev/null +++ b/admin/syntax-highlight/haproxy.vim @@ -0,0 +1,164 @@ +" Vim syntax file +" Language: HAProxy +" Maintainer: Bruno Michel <brmichel@free.fr> +" Last Change: Mar 30, 2007 +" Version: 0.3 +" URL: http://haproxy.1wt.eu/ +" URL: http://vim.sourceforge.net/scripts/script.php?script_id=1845 + +" It is suggested to add the following line to $HOME/.vimrc : +" au BufRead,BufNewFile haproxy* set ft=haproxy + +" For version 5.x: Clear all syntax items +" For version 6.x: Quit when a syntax file was already loaded +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +if version >= 600 + setlocal iskeyword=_,-,a-z,A-Z,48-57 +else + set iskeyword=_,-,a-z,A-Z,48-57 +endif + + +" Escaped chars +syn match hapEscape +\\\(\\\| \|n\|r\|t\|#\|x\x\x\)+ + +" Comments +syn match hapComment /#.*$/ contains=hapTodo +syn keyword hapTodo contained TODO FIXME XXX +syn case ignore + +" Sections +syn match hapSection /^\s*\(global\|defaults\)/ +syn match hapSection /^\s*\(listen\|frontend\|backend\|ruleset\)/ skipwhite nextgroup=hapSectLabel +syn match hapSectLabel /\S\+/ skipwhite nextgroup=hapIp1 contained +syn match hapIp1 /\(\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\)\?:\d\{1,5}/ nextgroup=hapIp2 contained +syn match hapIp2 /,\(\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\)\?:\d\{1,5}/hs=s+1 nextgroup=hapIp2 contained + +" Parameters +syn keyword hapParam chroot cliexp +syn keyword hapParam daemon debug disabled +syn keyword hapParam enabled +syn keyword hapParam fullconn +syn keyword hapParam gid group +syn keyword hapParam maxconn monitor-uri +syn keyword hapParam noepoll nopoll +syn keyword hapParam pidfile +syn keyword hapParam quiet +syn keyword hapParam redispatch retries +syn keyword hapParam reqallow reqdel reqdeny reqpass reqtarpit skipwhite nextgroup=hapRegexp +syn keyword hapParam reqiallow reqidel reqideny reqipass reqitarpit skipwhite nextgroup=hapRegexp +syn keyword hapParam rspdel rspdeny skipwhite nextgroup=hapRegexp +syn keyword hapParam rspidel rspideny skipwhite nextgroup=hapRegexp +syn keyword hapParam reqsetbe reqisetbe skipwhite nextgroup=hapRegexp2 +syn keyword hapParam reqadd reqiadd rspadd rspiadd +syn keyword hapParam server source srvexp +syn keyword hapParam uid ulimit-n user +syn keyword hapParam reqrep reqirep rsprep rspirep skipwhite nextgroup=hapRegexp +syn keyword hapParam errorloc errorloc302 errorloc303 skipwhite nextgroup=hapStatus +syn keyword hapParam default_backend skipwhite nextgroup=hapSectLabel +syn keyword hapParam appsession skipwhite nextgroup=hapAppSess +syn keyword hapParam bind skipwhite nextgroup=hapIp1 +syn keyword hapParam balance skipwhite nextgroup=hapBalance +syn keyword hapParam cookie skipwhite nextgroup=hapCookieNam +syn keyword hapParam capture skipwhite nextgroup=hapCapture +syn keyword hapParam dispatch skipwhite nextgroup=hapIpPort +syn keyword hapParam source skipwhite nextgroup=hapIpPort +syn keyword hapParam mode skipwhite nextgroup=hapMode +syn keyword hapParam monitor-net skipwhite nextgroup=hapIPv4Mask +syn keyword hapParam option skipwhite nextgroup=hapOption +syn keyword hapParam stats skipwhite nextgroup=hapStats +syn keyword hapParam server skipwhite nextgroup=hapServerN +syn keyword hapParam source skipwhite nextgroup=hapServerEOL +syn keyword hapParam log skipwhite nextgroup=hapGLog,hapLogIp + +" Options and additional parameters +syn keyword hapAppSess contained len timeout +syn keyword hapBalance contained roundrobin source +syn keyword hapLen contained len +syn keyword hapGLog contained global +syn keyword hapMode contained http tcp health +syn keyword hapOption contained abortonclose allbackups checkcache clitcpka dontlognull forwardfor +syn keyword hapOption contained httpchk httpclose httplog keepalive logasap persist srvtcpka ssl-hello-chk +syn keyword hapOption contained tcplog tcpka tcpsplice +syn keyword hapOption contained except skipwhite nextgroup=hapIPv4Mask +syn keyword hapStats contained uri realm auth scope enable +syn keyword hapLogFac contained kern user mail daemon auth syslog lpr news nextgroup=hapLogLvl skipwhite +syn keyword hapLogFac contained uucp cron auth2 ftp ntp audit alert cron2 nextgroup=hapLogLvl skipwhite +syn keyword hapLogFac contained local0 local1 local2 local3 local4 local5 local6 local7 nextgroup=hapLogLvl skipwhite +syn keyword hapLogLvl contained emerg alert crit err warning notice info debug +syn keyword hapCookieKey contained rewrite insert nocache postonly indirect prefix nextgroup=hapCookieKey skipwhite +syn keyword hapCapture contained cookie nextgroup=hapNameLen skipwhite +syn keyword hapCapture contained request response nextgroup=hapHeader skipwhite +syn keyword hapHeader contained header nextgroup=hapNameLen skipwhite +syn keyword hapSrvKey contained backup cookie check inter rise fall port source minconn maxconn weight usesrc +syn match hapStatus contained /\d\{3}/ +syn match hapIPv4Mask contained /\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\(\/\d\{1,2}\)\?/ +syn match hapLogIp contained /\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}/ nextgroup=hapLogFac skipwhite +syn match hapIpPort contained /\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}:\d\{1,5}/ +syn match hapServerAd contained /\d\{1,3}\.\d\{1,3}\.\d\{1,3}\.\d\{1,3}\(:[+-]\?\d\{1,5}\)\?/ nextgroup=hapSrvEOL skipwhite +syn match hapNameLen contained /\S\+/ nextgroup=hapLen skipwhite +syn match hapCookieNam contained /\S\+/ nextgroup=hapCookieKey skipwhite +syn match hapServerN contained /\S\+/ nextgroup=hapServerAd skipwhite +syn region hapSrvEOL contained start=/\S/ end=/$/ contains=hapSrvKey +syn region hapRegexp contained start=/\S/ end=/\(\s\|$\)/ skip=/\\ / nextgroup=hapRegRepl skipwhite +syn region hapRegRepl contained start=/\S/ end=/$/ contains=hapComment,hapEscape,hapBackRef +syn region hapRegexp2 contained start=/\S/ end=/\(\s\|$\)/ skip=/\\ / nextgroup=hapSectLabel skipwhite +syn match hapBackref contained /\\\d/ + + +" Transparent is a Vim keyword, so we need a regexp to match it +syn match hapParam +transparent+ +syn match hapOption +transparent+ contained + + +" Define the default highlighting. +" For version 5.7 and earlier: only when not done already +" For version 5.8 and later: only when an item doesn't have highlighting yet +if version < 508 + command -nargs=+ HiLink hi link <args> +else + command -nargs=+ HiLink hi def link <args> +endif + +HiLink hapEscape SpecialChar +HiLink hapBackRef Special +HiLink hapComment Comment +HiLink hapTodo Todo +HiLink hapSection Constant +HiLink hapSectLabel Identifier +HiLink hapParam Keyword + +HiLink hapRegexp String +HiLink hapRegexp2 hapRegexp +HiLink hapIp1 Number +HiLink hapIp2 hapIp1 +HiLink hapLogIp hapIp1 +HiLink hapIpPort hapIp1 +HiLink hapIPv4Mask hapIp1 +HiLink hapServerAd hapIp1 +HiLink hapStatus Number + +HiLink hapOption Operator +HiLink hapAppSess hapOption +HiLink hapBalance hapOption +HiLink hapCapture hapOption +HiLink hapCookieKey hapOption +HiLink hapHeader hapOption +HiLink hapGLog hapOption +HiLink hapLogFac hapOption +HiLink hapLogLvl hapOption +HiLink hapMode hapOption +HiLink hapStats hapOption +HiLink hapLen hapOption +HiLink hapSrvKey hapOption + + +delcommand HiLink + +let b:current_syntax = "haproxy" +" vim: ts=8 diff --git a/admin/systemd/Makefile b/admin/systemd/Makefile new file mode 100644 index 0000000..e542c23 --- /dev/null +++ b/admin/systemd/Makefile @@ -0,0 +1,8 @@ +PREFIX = /usr/local +SBINDIR = $(PREFIX)/sbin + +haproxy.service: haproxy.service.in + sed -e 's:@SBINDIR@:'$(strip $(SBINDIR))':' $< > $@ + +clean: + rm -f haproxy.service diff --git a/admin/systemd/haproxy.service.in b/admin/systemd/haproxy.service.in new file mode 100644 index 0000000..eb1ad42 --- /dev/null +++ b/admin/systemd/haproxy.service.in @@ -0,0 +1,37 @@ +[Unit] +Description=HAProxy Load Balancer +After=network-online.target +Wants=network-online.target + +[Service] +EnvironmentFile=-/etc/default/haproxy +EnvironmentFile=-/etc/sysconfig/haproxy +Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "EXTRAOPTS=-S /run/haproxy-master.sock" +ExecStart=@SBINDIR@/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS +ExecReload=@SBINDIR@/haproxy -Ws -f $CONFIG -c -q $EXTRAOPTS +ExecReload=/bin/kill -USR2 $MAINPID +KillMode=mixed +Restart=always +SuccessExitStatus=143 +Type=notify + +# The following lines leverage SystemD's sandboxing options to provide +# defense in depth protection at the expense of restricting some flexibility +# in your setup (e.g. placement of your configuration files) or possibly +# reduced performance. See systemd.service(5) and systemd.exec(5) for further +# information. + +# NoNewPrivileges=true +# ProtectHome=true +# If you want to use 'ProtectSystem=strict' you should whitelist the PIDFILE, +# any state files and any other files written using 'ReadWritePaths' or +# 'RuntimeDirectory'. +# ProtectSystem=true +# ProtectKernelTunables=true +# ProtectKernelModules=true +# ProtectControlGroups=true +# If your SystemD version supports them, you can add: @reboot, @swap, @sync +# SystemCallFilter=~@cpu-emulation @keyring @module @obsolete @raw-io + +[Install] +WantedBy=multi-user.target diff --git a/admin/wireshark-dissectors/peers/Makefile b/admin/wireshark-dissectors/peers/Makefile new file mode 100644 index 0000000..95149e7 --- /dev/null +++ b/admin/wireshark-dissectors/peers/Makefile @@ -0,0 +1,17 @@ +CFLAGS = `pkg-config --cflags wireshark` -g -fPIC $(OPTS) +LDFLAGS = `pkg-config --libs wireshark` + +NAME = packet-happp.so +OBJS = packet-happp.o + +plugins=$(HOME)/.wireshark/plugins/ + +$(NAME): $(OBJS) + $(CC) -shared $(LDFLAGS) $(OBJS) -o $@ + +install: $(NAME) + install -d $(DESTDIR)$(plugins) + install -m 0755 $(NAME) $(DESTDIR)$(plugins) + +clean: + rm $(NAME) $(OBJS) diff --git a/admin/wireshark-dissectors/peers/README b/admin/wireshark-dissectors/peers/README new file mode 100644 index 0000000..83b57d2 --- /dev/null +++ b/admin/wireshark-dissectors/peers/README @@ -0,0 +1,78 @@ +------------------------------------------------------------------------ +How to build wireshark with HAProxy Peers Protocol dissection support. +------------------------------------------------------------------------ + +Please note that at this time, HAProxy Peers Protocol dissection is not supported +on Windows systems (could not be tested). + +1) File list +------------- + - packet-happp.c: source code for HAProxy Peers Protocol (HAPPP) dissection + support. + - wireshark.happp.dissector.patch: a patch file for wireshark sources to enable HAPPP + dissection support. Note that this patch file modifies only two files: + (epan/dissectors/CMakeLists.txt and epan/dissectors/Makefile.am) to add + packet-happp.c file DISSECTOR_SRC variable which list all wireshark + - README: this file. + +2a) To build wireshark with HAPPP dissection support +--------------------------------------------------- + - Download wireshark sources: + $ git clone https://code.wireshark.org/review/wireshark + - copy packet-happp.c file to epan/dissectors/ directory. + - apply wireshark.happp.dissector.patch file to wireshark source directory. + - build wireshark (see https://www.wireshark.org/docs/wsdg_html_chunked/): + $ ./autogen.sh + $ ./configure + $ make + +2b) Alternative: build the HAPPP dissector as a wireshark plugin +----------------------------------------------------------------- +If you don't want to build completely wireshark, you can build the dissector as +a plugin. + +You will need the development package of your distribution, which is +"libwireshark-dev" for debian based distribution and "wireshark-dev" for +redhat-based ones. + +$ make + +It is possible that depending on your distribution the compilation may fail +with such an error: + + packet-happp.c:40:10: fatal error: ws_version.h: No such file or directory + #include <ws_version.h> + +In this case try to build this plugins with this OPTS variable: + +$ OPTS=-DWITHOUT_WS_VERSION make + +To install it in your home directory: + +$ make install + +The plugin will be installed in ~/.wireshark/plugins/ by default, but you can +change this path by setting the "plugins" variable. If it didn't work, check +the paths in "Help > About Wireshark > Folders > Personal Plugins" which should +give you the right path to use. + +In some distribution it will be in ~/.local/lib/wireshark/ so you will need to +install it this way: + +$ make install plugins=~/.local/lib/wireshark/plugins/3.2/epan/ + +If you want to install it in the system directory you can do it this way, the +righ path is also in the Folder window. Change the plugins variable this way: + +$ sudo make install plugins=/usr/lib64/wireshark/plugins/3.2/epan/ + +Be careful to use the right version number in the path. + +3) Check if you have the dissector in wireshark +----------------------------------------------- +To verify if the protocol was well loaded by your wireshark, open the Supported +Protocols window in "View > Internals > Supported Protocols" and look for +"HAPPP". + +In the case of a plugin, you should see your plugin loaded in "Help > About +Wireshark > Plugins". diff --git a/admin/wireshark-dissectors/peers/packet-happp.c b/admin/wireshark-dissectors/peers/packet-happp.c new file mode 100644 index 0000000..581262f --- /dev/null +++ b/admin/wireshark-dissectors/peers/packet-happp.c @@ -0,0 +1,1679 @@ +/* packet-happp.c + * Routines for HAProxy Peers Protocol (HAPPP) dissection + * Copyright 2016, Frédéric Lécaille <flecaille@haproxy.com> + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <stdio.h> +#include <inttypes.h> +#include <inttypes.h> +#include <arpa/inet.h> + +#include <config.h> + +#include <epan/to_str.h> +#include <epan/packet.h> +#include <epan/prefs.h> +#include <epan/conversation.h> +#include <epan/strutil.h> +#include <epan/dissectors/packet-tcp.h> +#include <epan/tvbuff.h> + +#ifndef WITHOUT_WS_VERSION +#include <ws_version.h> +#endif + +#ifndef WIRESHARK_VERSION_MAJOR +#define WIRESHARK_VERSION_MAJOR VERSION_MAJOR +#endif +#ifndef WIRESHARK_VERSION_MINOR +#define WIRESHARK_VERSION_MINOR VERSION_MINOR +#endif +#ifndef WIRESHARK_VERSION_MICRO +#define WIRESHARK_VERSION_MICRO VERSION_MICRO +#endif + +#define HAPP_STR(str) #str +#define HAPP_XSTR(str) HAPP_STR(str) + +WS_DLL_PUBLIC_DEF const gchar plugin_version[] = "0.0.1"; +WS_DLL_PUBLIC_DEF const gchar plugin_release[] = HAPP_XSTR(WIRESHARK_VERSION_MAJOR.WIRESHARK_VERSION_MINOR); +WS_DLL_PUBLIC_DEF const int plugin_want_major = WIRESHARK_VERSION_MAJOR; +WS_DLL_PUBLIC_DEF const int plugin_want_minor = WIRESHARK_VERSION_MINOR; +WS_DLL_PUBLIC void plugin_register(void); + + +#define HAPPP_PROTOCOL "HAProxyS" +#define HAPPP_MSG_MIN_LEN 2 + +/* Status messages are the shortest ones (3 digits followed by a LF character) */ +#define STATUS_HANDSHAKE_SUCCEEDED "200" +#define STATUS_TRY_AGAIN_LATER "300" +#define STATUS_PROTOCOL_ERROR "501" +#define STATUS_BAD_VERSION "502" +#define STATUS_LOCAL_PEER_NAME_MISMATCH "503" +#define STATUS_REMOTE_PEER_NAME_MISMATCH "504" + +#include <stdio.h> +#include <ctype.h> +#include <stdarg.h> + + +#ifdef DEBUG +static unsigned char dbg_buf[16 << 10]; + +__attribute__((format (printf, 3, 4))) +void hexdump(const unsigned char *buf, size_t buflen, const char *title_fmt, ...) +{ + size_t i; + va_list ap; + const unsigned char *p; + char str_buf[2 + 1 + 16 + 1 + 1]; + + va_start(ap, title_fmt); + vfprintf(stderr, title_fmt, ap); + va_end(ap); + + p = buf; + str_buf[0] = str_buf[1] = ' '; + str_buf[2] = '|'; + + for (i = 0; i < buflen; i++) { + if (!(i & 0xf)) + fprintf(stderr, "%08X: ", i); + fprintf(stderr, " %02x", *p); + if (isalnum(*p)) + str_buf[(i & 0xf) + 3] = *p; + else + str_buf[(i & 0xf) + 3] = '.'; + if ((i & 0xf) == 0xf || i == buflen -1) { + size_t k; + + for (k = 0; k < (0x10 - (i & 0xf) - 1); k++) + fprintf(stderr, " "); + str_buf[(i & 0xf) + 4] = '|'; + str_buf[(i & 0xf) + 5 ] = '\0'; + fprintf(stderr, "%s\n", str_buf); + } + p++; + } +} + +void hexdump_tvb(tvbuff_t *tvb, const gint offset, size_t len) +{ + len = len > sizeof dbg_buf ? sizeof dbg_buf : len; + if (tvb_memcpy(tvb, dbg_buf, offset, len)) { + hexdump(dbg_buf, len, "tvb buff (%zu bytes):\n", len); + } else + fprintf(stderr, "tvb buff COPY FAILED\n"); +} +#endif + +/* HAPPP message classes */ +enum { + PEER_MSG_CLASS_CONTROL = 0, + PEER_MSG_CLASS_ERROR, + PEER_MSG_CLASS_STICKTABLE = 0x0a, + PEER_MSG_CLASS_RESERVED = 0xff, +}; + +enum { + CONTROL_CLASS_INDEX, + ERROR_CLASS_INDEX, + STICK_TABLE_CLASS_INDEX, + RESERVED_CLASS_INDEX, +}; + +/* Control messages */ +enum { + PEER_MSG_CTRL_RESYNCREQ = 0, + PEER_MSG_CTRL_RESYNCFINISHED, + PEER_MSG_CTRL_RESYNCPARTIAL, + PEER_MSG_CTRL_RESYNCCONFIRM, + PEER_MSG_CTRL_HEARTBEAT, +}; + +/* Error messages */ +enum { + PEER_MSG_ERR_PROTOCOL = 0, + PEER_MSG_ERR_SIZELIMIT, +}; + +/* Stick table messages */ +enum { + PEER_MSG_STKT_UPDATE = 0x80, + PEER_MSG_STKT_INCUPDATE, + PEER_MSG_STKT_DEFINE, + PEER_MSG_STKT_SWITCH, + PEER_MSG_STKT_ACK, + PEER_MSG_STKT_UPDATE_TIMED, + PEER_MSG_STKT_INCUPDATE_TIMED, +}; + +/* This is the different key types of the stick tables. + * Same definitions as in HAProxy sources. + */ +enum { + SMP_T_ANY, /* any type */ + SMP_T_BOOL, /* boolean */ + SMP_T_SINT, /* signed 64bits integer type */ + SMP_T_ADDR, /* ipv4 or ipv6, only used for input type compatibility */ + SMP_T_IPV4, /* ipv4 type */ + SMP_T_IPV6, /* ipv6 type */ + SMP_T_STR, /* char string type */ + SMP_T_BIN, /* buffer type */ + SMP_T_METH, /* contain method */ + SMP_TYPES /* number of types, must always be last */ +}; + +/* The types of data we can store in a stick table. + * Same definitions as in HAProxy sources. + */ +enum { + STKT_DT_SERVER_ID, /* the server ID to use with this stream if > 0 */ + STKT_DT_GPT0, /* General Purpose Flag 0. */ + STKT_DT_GPC0, /* General Purpose Counter 0 (unsigned 32-bit integer) */ + STKT_DT_GPC0_RATE, /* General Purpose Counter 0's event rate */ + STKT_DT_CONN_CNT, /* cumulated number of connections */ + STKT_DT_CONN_RATE, /* incoming connection rate */ + STKT_DT_CONN_CUR, /* concurrent number of connections */ + STKT_DT_SESS_CNT, /* cumulated number of sessions (accepted connections) */ + STKT_DT_SESS_RATE, /* accepted sessions rate */ + STKT_DT_HTTP_REQ_CNT, /* cumulated number of incoming HTTP requests */ + STKT_DT_HTTP_REQ_RATE, /* incoming HTTP request rate */ + STKT_DT_HTTP_ERR_CNT, /* cumulated number of HTTP requests errors (4xx) */ + STKT_DT_HTTP_ERR_RATE, /* HTTP request error rate */ + STKT_DT_BYTES_IN_CNT, /* cumulated bytes count from client to servers */ + STKT_DT_BYTES_IN_RATE, /* bytes rate from client to servers */ + STKT_DT_BYTES_OUT_CNT, /* cumulated bytes count from servers to client */ + STKT_DT_BYTES_OUT_RATE, /* bytes rate from servers to client */ + STKT_STATIC_DATA_TYPES, /* number of types above */ +}; + +/* The types of data in stick stored in stick tables. + * Same definitions as in HAProxy sources. + */ +enum { + STD_T_SINT = 0, /* signed int */ + STD_T_UINT, /* unsigned int */ + STD_T_ULL, /* unsigned long long */ + STD_T_FRQP, /* freq_ctr structure made of three unsigned int */ +}; + +/* Prototypes */ +void proto_reg_handoff_happp(void); +void proto_register_happp(void); + +/* Initialize the protocol and registered fields */ +static int proto_happp = -1; +static int hf_happp_fake = -1; +static int hf_happp_version = -1; +static int hf_happp_remotepeerid = -1; +static int hf_happp_localpeerid = -1; +static int hf_happp_processpid = -1; +static int hf_happp_relativepid = -1; +static int hf_happp_status = -1; +static int hf_happp_msg = -1; +static int hf_happp_msg_class = -1; +static int hf_happp_msg_type = -1; +static int hf_happp_msg_len = -1; +static int hf_happp_stkt_def_id = -1; +static int hf_happp_stkt_def_name_len = -1; +static int hf_happp_stkt_def_name_value = -1; +static int hf_happp_stkt_def_key_type = -1; +static int hf_happp_stkt_def_key_len = -1; +static int hf_happp_stkt_def_data_types = -1; +static int hf_happp_stkt_updt_update_id = -1; +static int hf_happp_stkt_updt_expire = -1; +static int hf_happp_stkt_updt_key_len = -1; +static int hf_happp_stkt_updt_key_ipv4_value = -1; +static int hf_happp_stkt_updt_key_str_value = -1; +static int hf_happp_stkt_updt_key_int_value = -1; +static int hf_happp_stkt_updt_key_bytes_value = -1; +static int hf_happp_stkt_updt_data_server_id = -1; +static int hf_happp_stkt_updt_data_gpt0 = -1; +static int hf_happp_stkt_updt_data_gpc0 = -1; +static int hf_happp_stkt_updt_data_gpc0_rate_curr_tick = -1; +static int hf_happp_stkt_updt_data_gpc0_rate_curr_ctr = -1; +static int hf_happp_stkt_updt_data_gpc0_rate_prev_ctr = -1; +static int hf_happp_stkt_updt_data_conn_cnt = -1; +static int hf_happp_stkt_updt_data_conn_rate_curr_tick = -1; +static int hf_happp_stkt_updt_data_conn_rate_curr_ctr = -1; +static int hf_happp_stkt_updt_data_conn_rate_prev_ctr = -1; +static int hf_happp_stkt_updt_data_conn_cur = -1; +static int hf_happp_stkt_updt_data_sess_cnt = -1; +static int hf_happp_stkt_updt_data_sess_rate_curr_tick = -1; +static int hf_happp_stkt_updt_data_sess_rate_curr_ctr = -1; +static int hf_happp_stkt_updt_data_sess_rate_prev_ctr = -1; +static int hf_happp_stkt_updt_data_http_req_cnt = -1; +static int hf_happp_stkt_updt_data_http_req_rate_curr_tick = -1; +static int hf_happp_stkt_updt_data_http_req_rate_curr_ctr = -1; +static int hf_happp_stkt_updt_data_http_req_rate_prev_ctr= -1; +static int hf_happp_stkt_updt_data_http_err_cnt = -1; +static int hf_happp_stkt_updt_data_http_err_rate_curr_tick = -1; +static int hf_happp_stkt_updt_data_http_err_rate_curr_ctr = -1; +static int hf_happp_stkt_updt_data_http_err_rate_prev_ctr = -1; +static int hf_happp_stkt_updt_data_bytes_in_cnt = -1; +static int hf_happp_stkt_updt_data_bytes_in_rate_curr_tick = -1; +static int hf_happp_stkt_updt_data_bytes_in_rate_curr_ctr = -1; +static int hf_happp_stkt_updt_data_bytes_in_rate_prev_ctr = -1; +static int hf_happp_stkt_updt_data_bytes_out_cnt = -1; +static int hf_happp_stkt_updt_data_bytes_out_rate_curr_tick = -1; +static int hf_happp_stkt_updt_data_bytes_out_rate_curr_ctr = -1; +static int hf_happp_stkt_updt_data_bytes_out_rate_prev_ctr = -1; +static int hf_happp_stkt_updt_ack_table_id = -1; +static int hf_happp_stkt_updt_ack_update_id = -1; + +struct happp_cv_data_t { + /* Same thing for the type of the the stick table keys */ + uint64_t stkt_key_type; + + /* Same thing for the length of the stick table keys. + * Note that this is true only for key types different of SMT_T_STR (strings) + * and SMT_T_SINT (signed ints). + */ + uint64_t stkt_key_len; + + /* Same thing for the types of the stick table data */ + uint64_t stkt_data_types; + void *data; +}; + +struct hf_stkt_data_type { + const char *name; + unsigned int type; + int *hf_ids[3]; + size_t hf_ids_len; +}; + +struct hf_stkt_data_type hf_stkt_data_types[] = { + [STKT_DT_SERVER_ID] = { + .name = "server_id", + .type = STD_T_SINT, + .hf_ids = { + &hf_happp_stkt_updt_data_server_id, + }, + .hf_ids_len = 1, + }, + [STKT_DT_GPT0] = { + .name = "gpt0", + .type = STD_T_UINT, + .hf_ids = { + &hf_happp_stkt_updt_data_gpt0, + }, + .hf_ids_len = 1, + }, + [STKT_DT_GPC0] = { + .name = "gpc0", + .type = STD_T_UINT, + .hf_ids = { + &hf_happp_stkt_updt_data_gpc0, + }, + .hf_ids_len = 1, + }, + [STKT_DT_GPC0_RATE] = { + .name = "gpc0_rate", + .type = STD_T_FRQP, + .hf_ids = { + &hf_happp_stkt_updt_data_gpc0_rate_curr_tick, + &hf_happp_stkt_updt_data_gpc0_rate_curr_ctr, + &hf_happp_stkt_updt_data_gpc0_rate_prev_ctr, + }, + .hf_ids_len = 3, + }, + [STKT_DT_CONN_CNT] = { + .name = "conn_cnt", + .type = STD_T_UINT, + .hf_ids = { + &hf_happp_stkt_updt_data_conn_cnt, + }, + .hf_ids_len = 1, + }, + [STKT_DT_CONN_RATE] = { + .name = "conn_rate", + .type = STD_T_FRQP, + .hf_ids = { + &hf_happp_stkt_updt_data_conn_rate_curr_tick, + &hf_happp_stkt_updt_data_conn_rate_curr_ctr, + &hf_happp_stkt_updt_data_conn_rate_prev_ctr, + }, + .hf_ids_len = 3, + }, + [STKT_DT_CONN_CUR] = { + .name = "conn_cur", + .type = STD_T_UINT, + .hf_ids = { + &hf_happp_stkt_updt_data_conn_cur, + }, + .hf_ids_len = 1, + }, + [STKT_DT_SESS_CNT] = { + .name = "sess_cnt", + .type = STD_T_UINT, + .hf_ids = { + &hf_happp_stkt_updt_data_sess_cnt, + }, + .hf_ids_len = 1, + }, + [STKT_DT_SESS_RATE] = { + .name = "sess_rate", + .type = STD_T_FRQP, + .hf_ids = { + &hf_happp_stkt_updt_data_sess_rate_curr_tick, + &hf_happp_stkt_updt_data_sess_rate_curr_ctr, + &hf_happp_stkt_updt_data_sess_rate_prev_ctr, + }, + .hf_ids_len = 3, + }, + [STKT_DT_HTTP_REQ_CNT] = { + .name = "http_req_cnt", + .type = STD_T_UINT, + .hf_ids = { + &hf_happp_stkt_updt_data_http_req_cnt, + }, + .hf_ids_len = 1, + }, + [STKT_DT_HTTP_REQ_RATE] = { + .name = "http_req_rate", + .type = STD_T_FRQP, + .hf_ids = { + &hf_happp_stkt_updt_data_http_req_rate_curr_tick, + &hf_happp_stkt_updt_data_http_req_rate_curr_ctr, + &hf_happp_stkt_updt_data_http_req_rate_prev_ctr, + }, + .hf_ids_len = 3, + }, + [STKT_DT_HTTP_ERR_CNT] = { + .name = "http_err_cnt", + .type = STD_T_UINT, + .hf_ids = { + &hf_happp_stkt_updt_data_http_err_cnt, + }, + .hf_ids_len = 1, + }, + [STKT_DT_HTTP_ERR_RATE] = { + .name = "http_err_rate", + .type = STD_T_FRQP, + .hf_ids = { + &hf_happp_stkt_updt_data_http_err_rate_curr_tick, + &hf_happp_stkt_updt_data_http_err_rate_curr_ctr, + &hf_happp_stkt_updt_data_http_err_rate_prev_ctr, + }, + .hf_ids_len = 3, + }, + [STKT_DT_BYTES_IN_CNT] = { + .name = "bytes_in_cnt", + .type = STD_T_ULL, + .hf_ids = { + &hf_happp_stkt_updt_data_bytes_in_cnt, + }, + .hf_ids_len = 1, + }, + [STKT_DT_BYTES_IN_RATE] = { + .name = "bytes_in_rate", + .type = STD_T_FRQP, + .hf_ids = { + &hf_happp_stkt_updt_data_bytes_in_rate_curr_tick, + &hf_happp_stkt_updt_data_bytes_in_rate_curr_ctr, + &hf_happp_stkt_updt_data_bytes_in_rate_prev_ctr, + }, + .hf_ids_len = 3, + }, + [STKT_DT_BYTES_OUT_CNT] = { + .name = "bytes_out_cnt", + .type = STD_T_ULL, + .hf_ids = { + &hf_happp_stkt_updt_data_bytes_out_cnt, + }, + .hf_ids_len = 1, + }, + [STKT_DT_BYTES_OUT_RATE] = { + .name = "bytes_out_rate", + .type = STD_T_FRQP, + .hf_ids = { + &hf_happp_stkt_updt_data_bytes_out_rate_curr_tick, + &hf_happp_stkt_updt_data_bytes_out_rate_curr_ctr, + &hf_happp_stkt_updt_data_bytes_out_rate_prev_ctr, + }, + .hf_ids_len = 3, + }, +}; + + +/* Initialize the subtree pointers */ +static gint ett_happp = -1; +static gint ett_happp_msg = -1; + +static dissector_handle_t happp_tcp_handle; + +static const char *control_msg_type_str_from_byte(guint8 c); +static const char *error_msg_type_str_from_byte(guint8 c); +static const char *stkt_msg_type_str_from_byte(guint8 c); + +struct class_def_t { + const char *class_str; + const char *col_info_str; + const char *(*msg_type_str_func)(guint8 c); + unsigned int count; +}; + +static struct class_def_t class_def_tab[] = { + [CONTROL_CLASS_INDEX] = { + .class_str = "Control Class Message", + .col_info_str = "Ctl", + .msg_type_str_func = control_msg_type_str_from_byte, + }, + [ERROR_CLASS_INDEX] = { + .class_str = "Error Class Message", + .col_info_str = "Err", + .msg_type_str_func = error_msg_type_str_from_byte, + }, + [STICK_TABLE_CLASS_INDEX] = { + .class_str = "Stick Table Class Message", + .col_info_str = "Stkt", + .msg_type_str_func = stkt_msg_type_str_from_byte, + }, + [RESERVED_CLASS_INDEX] = { + .class_str = "Reserved Class Message", + .col_info_str = "Res", + } +}; + +static int control_class_index_from_byte(guint8 c) +{ + switch (c) { + case PEER_MSG_CLASS_CONTROL: + return CONTROL_CLASS_INDEX; + case PEER_MSG_CLASS_ERROR: + return ERROR_CLASS_INDEX; + case PEER_MSG_CLASS_STICKTABLE: + return STICK_TABLE_CLASS_INDEX; + case PEER_MSG_CLASS_RESERVED: + return RESERVED_CLASS_INDEX; + default: + return -1; + }; +} + +static const char *class_str_from_byte(guint8 c) +{ + int class_idx; + + class_idx = control_class_index_from_byte(c); + if (class_idx == -1) + return "N/A"; + + return class_def_tab[class_idx].class_str; +} + +static const char *control_msg_type_str_from_byte(guint8 c) +{ + switch (c) { + case PEER_MSG_CTRL_RESYNCREQ: + return "resync. request"; + case PEER_MSG_CTRL_RESYNCFINISHED: + return "resync. finished"; + case PEER_MSG_CTRL_RESYNCPARTIAL: + return "resync. partial"; + case PEER_MSG_CTRL_RESYNCCONFIRM: + return "resync. confirm"; + case PEER_MSG_CTRL_HEARTBEAT: + return "heartbeat"; + default: + return "Unknown"; + } +} + +static const char *stkt_msg_type_str_from_byte(guint8 c) +{ + switch (c) { + case PEER_MSG_STKT_UPDATE: + return "update"; + case PEER_MSG_STKT_INCUPDATE: + return "inc. update"; + case PEER_MSG_STKT_DEFINE: + return "definition"; + case PEER_MSG_STKT_SWITCH: + return "switch"; + case PEER_MSG_STKT_ACK: + return "ack"; + case PEER_MSG_STKT_UPDATE_TIMED: + return "update (with expiration)"; + case PEER_MSG_STKT_INCUPDATE_TIMED: + return "inc. update (with expiration)"; + default: + return "Unknown"; + } +} + +static const char *error_msg_type_str_from_byte(guint8 c) +{ + switch (c) { + case PEER_MSG_ERR_PROTOCOL: + return "protocol error"; + case PEER_MSG_ERR_SIZELIMIT: + return "limit size error"; + default: + return "Unknown"; + } +} + +#define MAX_ENC_LEN 10 +static uint64_t intdecode(unsigned char **str, size_t len) { + int i = 0; + uint64_t ret; + + if (len < 1 || len > MAX_ENC_LEN) { + *str = NULL; + return 0; + } + + ret = *(*str)++; + len--; + if ((ret & 0xf0) != 0xf0 || !len) + return ret; + + do { + /* As shifting value may be greater than 8 (size of **str in bits), + * uint64_t cast is required. + */ + ret += (uint64_t)**str << (4 + 7 * i++); + } while (len-- && (*(*str)++ & 0x80) == 0x80); + + return ret; +} + +static int dissect_happp_handshake_pdu(tvbuff_t *tvb, packet_info *pinfo, + proto_tree *happp_tree) +{ + int line_len, token_len; + gint offset = 0, next_offset; + const guchar *line, *line_end, *next_token; + size_t protocol_strlen; + + line_len = tvb_find_line_end(tvb, offset, -1, &next_offset, TRUE); + /* XXX TO DO */ + if (line_len == -1) + return -1; + + protocol_strlen = strlen(HAPPP_PROTOCOL); + + line = tvb_get_ptr(tvb, offset, line_len); + line_end = line + (next_offset - offset); + /* The line must contain at least HAPPP_PROTOCOL string followed by a space, + * then version string (at least one character) and a '\n' character. + */ + if (line_len >= (int)protocol_strlen + 3 && + !tvb_strncaseeql(tvb, 0, HAPPP_PROTOCOL, protocol_strlen)) { + /* This is an Hello message */ + col_set_str(pinfo->cinfo, COL_INFO, "Hello message"); + + token_len = get_token_len(line + protocol_strlen + 1, line_end, &next_token); + proto_tree_add_item(happp_tree, hf_happp_version, tvb, + offset + protocol_strlen + 1, token_len, + ENC_ASCII | ENC_NA); + + offset = next_offset; + line_len = tvb_find_line_end(tvb, offset, -1, &next_offset, TRUE); + /* XXX TO DO */ + if (line_len == -1) + return -1; + + line = tvb_get_ptr(tvb, offset, line_len); + line_end = line + (next_offset - offset); + /* Get next token: remotepeerid */ + token_len = get_token_len(line, line_end, &next_token); + if (!token_len) + return -1; + + proto_tree_add_item(happp_tree, hf_happp_remotepeerid, tvb, offset, + token_len, ENC_ASCII | ENC_NA); + + /* Retrieve next line */ + offset = next_offset; + line_len = tvb_find_line_end(tvb, offset, -1, &next_offset, TRUE); + /* XXX TO DO */ + if (line_len == -1) + return -1; + + line = tvb_get_ptr(tvb, offset, line_len); + line_end = line + (next_offset - offset); + /* Get next token: localpeerid */ + token_len = get_token_len(line, line_end, &next_token); + if (!token_len) + return -1; + + proto_tree_add_item(happp_tree, hf_happp_localpeerid, tvb, offset, + token_len, ENC_ASCII | ENC_NA); + offset += next_token - line; + line = next_token; + + /* Get next token: processpid */ + token_len = get_token_len(line, line_end, &next_token); + if (!token_len) + return -1; + + proto_tree_add_item(happp_tree, hf_happp_processpid, tvb, offset, + token_len, ENC_ASCII | ENC_NA); + offset += next_token - line; + line = next_token; + + /* Get next token: relativepid */ + token_len = get_token_len(line, line_end, &next_token); + if (!token_len) + return -1; + + proto_tree_add_item(happp_tree, hf_happp_relativepid, tvb, offset, + token_len, ENC_ASCII | ENC_NA); + offset += next_token - line; + line = next_token; + + } + else if (line_len == 3) { + col_set_str(pinfo->cinfo, COL_INFO, "Status message"); + token_len = get_token_len(line, line_end, &next_token); + if (!token_len) + return -1; + + proto_tree_add_item(happp_tree, hf_happp_status, tvb, offset, + token_len, ENC_ASCII | ENC_NA); + } + + return tvb_captured_length(tvb); +} + +/* Reset to zero all statistics counters of class_def_array */ +static void init_class_def_tab(struct class_def_t *class_def_array, size_t size) +{ + size_t i; + + for (i = 0; i < size; i++) + class_def_array[i].count = 0; +} + +/* Add statistics counting information about HAPPP message classes to + * info column (numbers of messages found in an HAPPP PDU by class). + */ +static inline void col_info_append_class(packet_info *pinfo, int class_index, + int *first_class) +{ + if (!class_def_tab[class_index].count) + return; + + col_append_fstr(pinfo->cinfo, COL_INFO, "%s%s=%u", + *first_class ? "" : " ", + class_def_tab[class_index].col_info_str, + class_def_tab[class_index].count); + class_def_tab[class_index].count = 0; + *first_class = 0; +} + + +static int intdecode_from_tvbuff(tvbuff_t *tvb, uint64_t *dec_val, + guint *offset, guint total) +{ + unsigned char *p, enc_buf[MAX_ENC_LEN]; + size_t max_enc_buf_len, left; + + left = total - *offset; + max_enc_buf_len = left < sizeof enc_buf ? left : sizeof enc_buf; + if (!tvb_memcpy(tvb, enc_buf, *offset, max_enc_buf_len)) + return -1; + + p = enc_buf; + *dec_val = intdecode(&p, max_enc_buf_len); + if (!p) + return -1; + + *offset += p - enc_buf; + + return 0; +} + +static int add_enc_field_to_happp_tree(int field_id, proto_tree *tree, tvbuff_t *tvb, + guint *offset, guint total, uint64_t *val) +{ + uint64_t dec_val; + size_t dec_val_len; + guint saved_offset; + + saved_offset = *offset; + if (intdecode_from_tvbuff(tvb, &dec_val, offset, total) < 0) + return -1; + + dec_val_len = *offset - saved_offset; + proto_tree_add_uint64_format_value(tree, field_id, tvb, saved_offset, + dec_val_len, dec_val, "%" PRIu64, dec_val); + + if (val) + *val = dec_val; + + return 0; +} + +static int add_int_field_to_happp_tree(int field_id, + tvbuff_t *tvb, proto_tree *tree, + guint *offset, guint total _U_) +{ + uint32_t val; + + if (!tvb_memcpy(tvb, &val, *offset, sizeof val)) + return -1; + + val = ntohl(val); + proto_tree_add_int_format_value(tree, field_id, tvb, *offset, + sizeof val, val, "%" PRId32, val); + *offset += sizeof val; + + return 0; +} + +static void dissect_happp_stkt_define_msg(tvbuff_t *tvb, packet_info *pinfo _U_, + proto_tree *tree, guint offset, guint total) +{ + uint64_t dec_val; + uint64_t stkt_key_type; + uint64_t stkt_key_len; + uint64_t stkt_data_types; + struct happp_cv_data_t *happp_cv_data; + conversation_t *cv; + + if (add_enc_field_to_happp_tree(hf_happp_stkt_def_id, tree, + tvb, &offset, total, NULL) < 0 || + add_enc_field_to_happp_tree(hf_happp_stkt_def_name_len, tree, + tvb, &offset, total, &dec_val) < 0) + return; + + /* Add the stick table name to HAPPP proto tree */ + proto_tree_add_item(tree, hf_happp_stkt_def_name_value, tvb, offset, dec_val, + ENC_ASCII | ENC_NA); + offset += dec_val; + + if (add_enc_field_to_happp_tree(hf_happp_stkt_def_key_type, tree, + tvb, &offset, total, &stkt_key_type) < 0 || + add_enc_field_to_happp_tree(hf_happp_stkt_def_key_len, tree, + tvb, &offset, total, &stkt_key_len) < 0 || + add_enc_field_to_happp_tree(hf_happp_stkt_def_data_types, tree, + tvb, &offset, total, &stkt_data_types) < 0) + return; + + cv = find_conversation(pinfo->num, &pinfo->src, &pinfo->dst, + pinfo->ptype, pinfo->srcport, pinfo->destport, 0); + if (!cv) + return; + + /* + * According to the documentation, it is not our responsibility + * to free this allocated memory. + */ + happp_cv_data = (struct happp_cv_data_t *)wmem_alloc(wmem_file_scope(), + sizeof *happp_cv_data); + if (!happp_cv_data) + return; + + happp_cv_data->stkt_key_type = stkt_key_type; + happp_cv_data->stkt_key_len = stkt_key_len; + happp_cv_data->stkt_data_types = stkt_data_types; + + conversation_add_proto_data(cv, proto_happp, happp_cv_data); +} + +static void dissect_happp_stkt_update_msg(tvbuff_t *tvb, packet_info *pinfo _U_, + proto_tree *tree, guint offset, guint total, + unsigned char msg_type_byte) +{ + unsigned int data_type; + uint64_t *stkt_key_type; + uint64_t *stkt_key_len; + struct happp_cv_data_t *happp_cv_data; + int has_update_id, has_exp; + conversation_t *cv; + + cv = find_conversation(pinfo->num, &pinfo->src, &pinfo->dst, + pinfo->ptype, pinfo->srcport, pinfo->destport, 0); + if (!cv) + return; + + happp_cv_data = (struct happp_cv_data_t *)conversation_get_proto_data(cv, proto_happp); + if (!happp_cv_data) + return; + + has_update_id = msg_type_byte == PEER_MSG_STKT_UPDATE || + msg_type_byte == PEER_MSG_STKT_UPDATE_TIMED; + has_exp = msg_type_byte == PEER_MSG_STKT_UPDATE_TIMED || + msg_type_byte == PEER_MSG_STKT_INCUPDATE_TIMED; + /* Add the stick table update ID to HAPPP tree */ + if (has_update_id && + add_int_field_to_happp_tree(hf_happp_stkt_updt_update_id, tvb, tree, + &offset, total) < 0) + return; + + if (has_exp && + add_int_field_to_happp_tree(hf_happp_stkt_updt_expire, tvb, tree, + &offset, total) < 0) + return; + + + stkt_key_type = &happp_cv_data->stkt_key_type; + stkt_key_len = &happp_cv_data->stkt_key_len; + + switch(*stkt_key_type) { + case SMP_T_STR: + if (add_enc_field_to_happp_tree(hf_happp_stkt_updt_key_len, tree, tvb, + &offset, total, stkt_key_len) < 0) + return; + + proto_tree_add_item(tree, hf_happp_stkt_updt_key_str_value, tvb, + offset, *stkt_key_len, ENC_ASCII | ENC_NA); + offset += *stkt_key_len; + break; + case SMP_T_SINT: + if (add_int_field_to_happp_tree(hf_happp_stkt_updt_key_int_value, tvb, tree, + &offset, total) < 0) + return; + + break; + case SMP_T_IPV4: + proto_tree_add_ipv4(tree, hf_happp_stkt_updt_key_ipv4_value, + tvb, offset, 4, tvb_get_ipv4(tvb, offset)); + offset += 4; + break; + default: + proto_tree_add_item(tree, hf_happp_stkt_updt_key_bytes_value, + tvb, offset, *stkt_key_len, ENC_NA); + offset += *stkt_key_len; + break; + } + + /* Data dissection */ + for (data_type = 0; + data_type < sizeof hf_stkt_data_types / sizeof *hf_stkt_data_types; + data_type++) { + struct hf_stkt_data_type *hf_stkt_dtype; + size_t i; + + if (!(happp_cv_data->stkt_data_types & (1 << data_type))) + continue; + + hf_stkt_dtype = &hf_stkt_data_types[data_type]; + + for (i = 0; i < hf_stkt_dtype->hf_ids_len; i++) + if (add_enc_field_to_happp_tree(*hf_stkt_dtype->hf_ids[i], tree, tvb, + &offset, total, NULL) < 0) + return; + } +} + +static void dissect_happp_stkt_ack_msg(tvbuff_t *tvb, packet_info *pinfo _U_, + proto_tree *tree, guint offset, guint total) +{ + if (add_enc_field_to_happp_tree(hf_happp_stkt_updt_ack_table_id, tree, tvb, + &offset, total, NULL) < 0) + return; + + if (add_int_field_to_happp_tree(hf_happp_stkt_updt_ack_update_id, tvb, tree, + &offset, total) < 0) + return; +} + +static void dissect_happp_stk_msg(tvbuff_t *tvb, packet_info *pinfo _U_, + proto_tree *tree, guint8 msg_type_byte, + guint offset, guint total) +{ + switch (msg_type_byte) { + case PEER_MSG_STKT_DEFINE: + dissect_happp_stkt_define_msg(tvb, pinfo, tree, offset, total); + break; + case PEER_MSG_STKT_UPDATE: + case PEER_MSG_STKT_INCUPDATE: + case PEER_MSG_STKT_UPDATE_TIMED: + case PEER_MSG_STKT_INCUPDATE_TIMED: + dissect_happp_stkt_update_msg(tvb, pinfo, tree, offset, total, msg_type_byte); + break; + case PEER_MSG_STKT_ACK: + dissect_happp_stkt_ack_msg(tvb, pinfo, tree, offset, total); + break; + }; + +} + +static void +dissect_happp_msg(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, + guint8 msg_class_byte, guint8 msg_type_byte, + guint *offset, guint total) +{ + unsigned char *p, enc_buf[MAX_ENC_LEN]; + uint64_t dec_msg_len; + size_t max_enc_buf_len, left, dec_val_len; + + left = total - *offset; + max_enc_buf_len = left < sizeof enc_buf ? left : sizeof enc_buf; + if (!tvb_memcpy(tvb, enc_buf, *offset, max_enc_buf_len)) + return; + + p = enc_buf; + dec_msg_len = intdecode(&p, max_enc_buf_len); + if (!p) + return; + + dec_val_len = p - enc_buf; + proto_tree_add_uint64_format_value(tree, hf_happp_msg_len, + tvb, *offset, dec_val_len, dec_msg_len, + "%" PRIu64, dec_msg_len); + *offset += dec_val_len; + + switch (msg_class_byte) { + case PEER_MSG_CLASS_STICKTABLE: + dissect_happp_stk_msg(tvb, pinfo, tree, msg_type_byte, *offset, total); + break; + } + + *offset += dec_msg_len; +} + +/* Code to actually dissect the packets */ +static int +dissect_happp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) +{ + /* Set up structures needed to add the protocol subtree and manage it */ + proto_item *item; + proto_tree *happp_tree; + /* Other misc. local variables. */ + guint total, offset; + int first_message, first_class, curr_class, prev_class; + guint8 first_byte; + size_t sizeof_class_def_tab; + + offset = 0; + first_message = first_class = 1; + total = tvb_reported_length(tvb); + + /* create display subtree for the protocol */ + item = proto_tree_add_item(tree, proto_happp, tvb, offset, -1, ENC_NA); + happp_tree = proto_item_add_subtree(item, ett_happp); + + /* Set the protocol column value */ + col_set_str(pinfo->cinfo, COL_PROTOCOL, "happp"); + + first_byte = (gchar)tvb_get_guint8(tvb, offset); + if (first_byte != PEER_MSG_CLASS_CONTROL && + first_byte != PEER_MSG_CLASS_ERROR && + first_byte != PEER_MSG_CLASS_STICKTABLE && + first_byte != PEER_MSG_CLASS_RESERVED) + return dissect_happp_handshake_pdu(tvb, pinfo, happp_tree); + + /* Reset class_def_tab message class counters */ + sizeof_class_def_tab = sizeof class_def_tab / sizeof *class_def_tab; + init_class_def_tab(class_def_tab, sizeof_class_def_tab); + + prev_class = curr_class = -1; + col_set_str(pinfo->cinfo, COL_INFO, "["); + while (offset < total) { + guint8 msg_class_byte, msg_type_byte; + const char *(*msg_type_str_func)(guint8 c); + struct class_def_t *class_def; + + if (first_message) { + msg_class_byte = first_byte; + } + else { + msg_class_byte = tvb_get_guint8(tvb, offset); + } + curr_class = control_class_index_from_byte(msg_class_byte); + if (curr_class == -1) + return -1; + + if (first_message) { + prev_class = curr_class; + first_message = 0; + } + + class_def = &class_def_tab[curr_class]; + class_def->count++; + msg_type_str_func = class_def->msg_type_str_func; + + /* Insert a line separator */ + proto_tree_add_item(happp_tree, hf_happp_fake, tvb, + offset, 0, + ENC_ASCII | ENC_NA); + proto_tree_add_uint_format_value(happp_tree, hf_happp_msg_class, + tvb, offset++, 1, msg_class_byte, + "%u (%s)", msg_class_byte, + class_str_from_byte(msg_class_byte)); + msg_type_byte = tvb_get_guint8(tvb, offset); + + /* First byte: message class */ + switch (msg_class_byte) { + case PEER_MSG_CLASS_CONTROL: + case PEER_MSG_CLASS_ERROR: + case PEER_MSG_CLASS_STICKTABLE: + /* Second byte: message type in the class */ + proto_tree_add_uint_format_value(happp_tree, hf_happp_msg_type, + tvb, offset++, 1, msg_type_byte, + "%u (%s)", msg_type_byte, + msg_type_str_func(msg_type_byte)); + break; + case PEER_MSG_CLASS_RESERVED: + col_append_str(pinfo->cinfo, COL_INFO, "NON IMPLEMENTED"); + break; + } + if (msg_class_byte >= PEER_MSG_CLASS_STICKTABLE) + dissect_happp_msg(tvb, pinfo, happp_tree, + msg_class_byte, msg_type_byte, &offset, total); + + /* Sequentially add counting information to info column about + * number of messages found by class in an HAPPP PDU. + * For instance if an HAPPP PDU contains this sequence of messages: + * 1 Control message - 2 Stick Table messages - 3 Control messages + * column information displays: [Ctl=1 Stkt=2 Ctl=3]. + */ + if (curr_class != prev_class) { + col_info_append_class(pinfo, prev_class, &first_class); + col_info_append_class(pinfo, curr_class, &first_class); + prev_class = curr_class; + } + else if (offset >= total) { + /* Last message */ + col_info_append_class(pinfo, curr_class, &first_class); + } + } + col_append_str(pinfo->cinfo, COL_INFO, "]"); + + return tvb_captured_length(tvb); +} + +static guint +get_happp_msg_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_) +{ + guint ret, len, left; + gint next_offset, line_len; + guint8 first_byte; + uint64_t dec_len; + int saved_offset; + + /* 0 means there is not enough data to get length. */ + ret = 0; + + len = tvb_reported_length(tvb); + left = len - offset; + if (left < HAPPP_MSG_MIN_LEN) + goto out; + + saved_offset = offset; + first_byte = (gchar)tvb_get_guint8(tvb, offset); + if (first_byte == PEER_MSG_CLASS_CONTROL || + first_byte == PEER_MSG_CLASS_ERROR || + first_byte == PEER_MSG_CLASS_RESERVED) { + ret = HAPPP_MSG_MIN_LEN; + } else if (first_byte == PEER_MSG_CLASS_STICKTABLE) { + int soff; + + left -= HAPPP_MSG_MIN_LEN; + offset += HAPPP_MSG_MIN_LEN; + soff = offset; + if (intdecode_from_tvbuff(tvb, &dec_len, &offset, len) < 0) + goto out; + + left -= offset - soff; + if (left < dec_len) + goto out; + + ret = dec_len + offset - saved_offset; + } else { + /* hello message: add line lengths to compute this message length. */ + for (;;) { + line_len = tvb_find_line_end(tvb, offset, -1, &next_offset, TRUE); + if (line_len == -1) + break; + + ret += line_len + 1; + offset += line_len + 1; + } + } + + out: + return ret; + } + +static int +dissect_happp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) +{ + tcp_dissect_pdus(tvb, pinfo, tree, TRUE, + HAPPP_MSG_MIN_LEN, get_happp_msg_len, dissect_happp_pdu, data); + + return tvb_captured_length(tvb); +} + +/* Register the protocol with Wireshark. + * + * This format is require because a script is used to build the C function that + * calls all the protocol registration. + */ +void +proto_register_happp(void) +{ + /* Setup list of header fields See Section 1.5 of README.dissector for + * details. */ + static hf_register_info hf[] = { + { + /* This one is used as separator between HAPPP messages */ + &hf_happp_fake, + { + ":-----------------------------------------------", "happp.fake", + FT_STRING, STR_ASCII, NULL, 0, "FAKE", HFILL + } + }, + { + &hf_happp_version, + { + "version", "happp.version", + FT_STRING, STR_ASCII, NULL, 0, "version", HFILL + } + }, + { + &hf_happp_remotepeerid, + { + "remotepeerid", "happp.remotepeerid", + FT_STRING, STR_ASCII, NULL, 0, "remote peer id", HFILL + } + }, + { + &hf_happp_localpeerid, + { + "localpeerid", "happp.localpeerid", + FT_STRING, STR_ASCII, NULL, 0, "local peer id", HFILL + } + }, + { + &hf_happp_processpid, + { + "processpid", "happp.processpid", + FT_STRING, STR_ASCII, NULL, 0, "process pid", HFILL + } + }, + { + &hf_happp_relativepid, + { + "relativepid", "happp.relativepid", + FT_STRING, STR_ASCII, NULL, 0, "relative pid", HFILL + } + }, + { + &hf_happp_status, + { + "status", "happp.status", + FT_STRING, STR_ASCII, NULL, 0, "status message", HFILL + } + }, + { + &hf_happp_msg, + { + "message", "happp.msg", + FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_msg_class, + { + "message class", "happp.msg.class", + FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_msg_type, + { + "message type", "happp.msg.type", + FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_msg_len, + { + "message length", "happp.msg.len", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_def_id, + { + " ID", "happp.msg.stkt.def.id", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_def_name_len, + { + " name length", "happp.msg.stkt.def.name.length", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_def_name_value, + { + " name", "happp.msg.stkt.def.name.value", + FT_STRING, STR_ASCII, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_def_key_type, + { + " key type", "happp.msg.stkt.def.key.type", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_def_key_len, + { + " key length", "happp.msg.stkt.def.key.len", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_def_data_types, + { + " data types", "happp.msg.stkt.def.data_types", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_update_id, + { + " update ID", "happp.msg.stkt.updt.update_id", + FT_INT32, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_expire, + { + " expiration", "happp.msg.stkt.updt.expiration", + FT_INT32, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_key_len, + { + " key length", "happp.msg.stkt.updt.key.len", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_key_str_value, + { + " key value", "happp.msg.stkt.updt.key.str.value", + FT_STRING, STR_ASCII, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_key_int_value, + { + " key value", "happp.msg.stkt.updt.key.int.value", + FT_INT32, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_key_ipv4_value, + { + " key IPv4 value", "happp.msg.stkt.updt.key.ipv4.value", + FT_IPv4, BASE_NONE, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_key_bytes_value, + { + " key value", "happp.msg.stkt.updt.key.bytes.value", + FT_BYTES, 0, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_server_id, + { + " server_id", "happp.msg.stkt.updt.data.server_id", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_gpt0, + { + " gpt0", "happp.msg.stkt.updt.data.gpt0", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_gpc0, + { + " gpc0", "happp.msg.stkt.updt.data.gpc0", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_gpc0_rate_curr_tick, + { + " gpc0 curr. tick", + "happp.msg.stkt.updt.data.gpc0_rate.curr_tick", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_gpc0_rate_curr_ctr, + { + " gpc0 curr. ctr.", + "happp.msg.stkt.updt.data.gpc0_rate.curr_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_gpc0_rate_prev_ctr, + { + " gpc0 prev. ctr.", + "happp.msg.stkt.updt.data.gpc0_rate.prev_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_conn_cnt, + { + " conn_cnt", + "happp.msg.stkt.updt.data.conn_cnt", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_conn_rate_curr_tick, + { + " conn_rate curr. tick", + "happp.msg.stkt.updt.data.conn_rate.curr_tick", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_conn_rate_curr_ctr, + { + " conn_rate curr. ctr.", + "happp.msg.stkt.updt.data.conn_rate.curr_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_conn_rate_prev_ctr, + { + " conn_rate prev. ctr.", + "happp.msg.stkt.updt.data.conn_rate.prev_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_conn_cur, + { + " conn_curr curr. tick", + "happp.msg.stkt.updt.data.conn_cur", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_sess_cnt, + { + " sess_cnt", "happp.msg.stkt.updt.data.sess_cnt", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_sess_rate_curr_tick, + { + " sess_rate curr. tick", + "happp.msg.stkt.updt.data.sess_rate.curr_tick", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_sess_rate_curr_ctr, + { + " sess_rate curr. ctr.", + "happp.msg.stkt.updt.data.sess_rate.curr_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_sess_rate_prev_ctr, + { + " sess_rate prev. ctr.", + "happp.msg.stkt.updt.data.sess_rate.prev_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_http_req_cnt, + { + " http_req_cnt", + "happp.msg.stkt.updt.data.http_req_cnt", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_http_req_rate_curr_tick, + { + " http_req_rate curr. tick", + "happp.msg.stkt.updt.data.http_req_rate.curr_tick", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_http_req_rate_curr_ctr, + { + " http_req_rate curr. ctr.", + "happp.msg.stkt.updt.data.http_req_rate.curr_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_http_req_rate_prev_ctr, + { + " http_req_rate prev. ctr.", + "happp.msg.stkt.updt.data.http_req_rate.prev_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_http_err_cnt, + { + " http_err_cnt", + "happp.msg.stkt.updt.data.http_err_cnt", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_http_err_rate_curr_tick, + { + " http_err_rate curr. tick", + "happp.msg.stkt.updt.data.http_err_rate.curr_tick", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_http_err_rate_curr_ctr, + { + " http_err_rate curr. ctr.", + "happp.msg.stkt.updt.data.http_err_rate.curr_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_http_err_rate_prev_ctr, + { + " http_err_rate prev. ctr.", + "happp.msg.stkt.updt.data.http_err_rate.prev_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_bytes_in_cnt, + { + " bytes_in_cnt", + "happp.msg.stkt.updt.data.bytes_in_cnt", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_bytes_in_rate_curr_tick, + { + " bytes_in_rate curr. tick", + "happp.msg.stkt.updt.data.bytes_in_rate.curr_tick", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_bytes_in_rate_curr_ctr, + { + " bytes_in_rate curr. ctr.", + "happp.msg.stkt.updt.data.bytes_in_rate.curr_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_bytes_in_rate_prev_ctr, + { + " bytes_in_rate prev. ctr.", + "happp.msg.stkt.updt.data.bytes_in_rate.prev_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_bytes_out_cnt, + { + " bytes_out_cnt", + "happp.msg.stkt.updt.data.bytes_out_cnt", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_bytes_out_rate_curr_tick, + { + " bytes_out_rate curr. tick", + "happp.msg.stkt.updt.data.bytes_out_rate.curr_tick", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_bytes_out_rate_curr_ctr, + { + " bytes_out_rate curr. ctr.", + "happp.msg.stkt.updt.data.bytes_out_rate.curr_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_data_bytes_out_rate_prev_ctr, + { + " bytes_out_rate prev. ctr.", + "happp.msg.stkt.updt.data.bytes_out_rate.prev_ctr", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_ack_table_id, + { + " remote table Id", + "happp.msg.stkt.updt.ack.table_id", + FT_UINT64, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + { + &hf_happp_stkt_updt_ack_update_id, + { + " update Id", "happp.msg.stkt.updt.ack.update_id", + FT_INT32, BASE_DEC, NULL, 0, NULL, HFILL + } + }, + }; + + /* Setup protocol subtree array */ + static gint *ett[] = { + &ett_happp, + &ett_happp_msg + }; + + /* Register the protocol name and description */ + proto_happp = proto_register_protocol("HAProxy Peers Protocol", "HAPPP", "happp"); + + /* Required function calls to register the header fields and subtrees */ + proto_register_field_array(proto_happp, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); +} + +static gboolean +dissect_happp_heur_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) +{ + size_t proto_strlen; + conversation_t *conversation; + + proto_strlen = strlen(HAPPP_PROTOCOL); + + if (tvb_captured_length(tvb) < 2) + return FALSE; + + if (tvb_get_guint8(tvb, 0) == PEER_MSG_CLASS_STICKTABLE && + tvb_get_guint8(tvb, 1) >= PEER_MSG_STKT_UPDATE && + tvb_get_guint8(tvb, 1) <= PEER_MSG_STKT_ACK) + goto found; + + if (tvb_captured_length(tvb) < proto_strlen + 1) + return FALSE; + + /* Check that we received a line beginning with HAPPP_PROTOCOL + * followed by a space character. + */ + if (tvb_strneql(tvb, 0, HAPPP_PROTOCOL, proto_strlen) || + tvb_get_guint8(tvb, proto_strlen) != ' ') + return FALSE; + + found: + conversation = find_or_create_conversation(pinfo); + if (!conversation) + return FALSE; + + conversation_set_dissector(conversation, happp_tcp_handle); + dissect_happp_tcp(tvb, pinfo, tree, data); + + return TRUE; +} + +/* Simpler form of proto_reg_handoff_happp which can be used if there are + * no prefs-dependent registration function calls. */ +void +proto_reg_handoff_happp(void) +{ + /* Use create_dissector_handle() to indicate that dissect_happp_tcp() + * returns the number of bytes it dissected (or 0 if it thinks the packet + * does not belong to HAProxy Peers Protocol). + */ + happp_tcp_handle = create_dissector_handle(dissect_happp_tcp, proto_happp); + heur_dissector_add("tcp", dissect_happp_heur_tcp, "HAPPP over TCP", "happp_tcp", + proto_happp, HEURISTIC_ENABLE); +} + + +void +plugin_register(void) +{ + static proto_plugin plug; + + plug.register_protoinfo = proto_register_happp; + plug.register_handoff = proto_reg_handoff_happp; + proto_register_plugin(&plug); +} diff --git a/admin/wireshark-dissectors/peers/wireshark.happp.dissector.patch b/admin/wireshark-dissectors/peers/wireshark.happp.dissector.patch new file mode 100644 index 0000000..c06134d --- /dev/null +++ b/admin/wireshark-dissectors/peers/wireshark.happp.dissector.patch @@ -0,0 +1,24 @@ +diff --git a/epan/dissectors/CMakeLists.txt b/epan/dissectors/CMakeLists.txt +index 38e2149..5f8cd49 100644 +--- a/epan/dissectors/CMakeLists.txt ++++ b/epan/dissectors/CMakeLists.txt +@@ -665,6 +665,7 @@ set(DISSECTOR_SRC + packet-h263.c + packet-h263p.c + packet-h264.c ++ packet-happp.c + packet-hartip.c + packet-hazelcast.c + packet-hci_h1.c +diff --git a/epan/dissectors/Makefile.am b/epan/dissectors/Makefile.am +index 70edc66..bc46235 100644 +--- a/epan/dissectors/Makefile.am ++++ b/epan/dissectors/Makefile.am +@@ -694,6 +694,7 @@ DISSECTOR_SRC = \ + packet-h263.c \ + packet-h263p.c \ + packet-h264.c \ ++ packet-happp.c \ + packet-hartip.c \ + packet-hazelcast.c \ + packet-hci_h1.c \ |