pf plugin: add very simple rule monitoring
authorStefan Rinkes <stefan.rinkes@gmail.com>
Sat, 16 Apr 2011 09:06:56 +0000 (11:06 +0200)
committerStefan Rinkes <stefan.rinkes@gmail.com>
Sat, 16 Apr 2011 09:06:56 +0000 (11:06 +0200)
src/pf.c
types.pfrules.db [new file with mode: 0644]

index b4d2a45..02eb5ae 100644 (file)
--- a/src/pf.c
+++ b/src/pf.c
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-
-#include <net/if.h>
-#include <net/pfvar.h>
-
-#include <limits.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-
-#ifndef TEST
-#include "collectd.h"
-#include "common.h"
-#include "plugin.h"
-#include "configfile.h"
-#else
-#include <err.h>
-typedef u_int64_t      counter_t;
-#endif
-
-#define PF_SOCKET "/dev/pf"
-
-struct pfdata {
-       int     pd_dev;
-};
-
-static struct pfdata   pd;
+#include "pfcommon.h"
 
 static int     pf_init(void);
 static int     pf_read(void);
@@ -80,16 +48,14 @@ pf_init(void)
 {
        struct pf_status        status;
 
-       memset(&pd, '\0', sizeof(pd));
-
-       if ((pd.pd_dev = open(PF_SOCKET, O_RDWR)) == -1) {
+       if ((dev = open(PF_SOCKET, O_RDWR)) == -1) {
                return (-1);
        }
-       if (ioctl(pd.pd_dev, DIOCGETSTATUS, &status) == -1) {
+       if (ioctl(dev, DIOCGETSTATUS, &status) == -1) {
                return (-1);
        }
 
-       close(pd.pd_dev);
+       close(dev);
        if (!status.running)
                return (-1);
 
@@ -106,14 +72,14 @@ pf_read(void)
        char            *lnames[] = LCNT_NAMES;
        char            *names[] = { "searches", "inserts", "removals" };
 
-       if ((pd.pd_dev = open(PF_SOCKET, O_RDWR)) == -1) {
+       if ((dev = open(PF_SOCKET, O_RDWR)) == -1) {
                return (-1);
        }
-       if (ioctl(pd.pd_dev, DIOCGETSTATUS, &status) == -1) {
+       if (ioctl(dev, DIOCGETSTATUS, &status) == -1) {
                return (-1);
        }
 
-       close(pd.pd_dev);
+       close(dev);
        for (i = 0; i < PFRES_MAX; i++)
                submit_counter("pf_counters", cnames[i], status.counters[i]);
        for (i = 0; i < LCNT_MAX; i++)
diff --git a/types.pfrules.db b/types.pfrules.db
new file mode 100644 (file)
index 0000000..5bf5c86
--- /dev/null
@@ -0,0 +1,8 @@
+scrub_states_current   value:GAUGE:U:U
+scrub_states_total     value:GAUGE:U:U
+scrub_evaluations      value:GAUGE:U:U
+scrub_bytes            value:GAUGE:U:U
+rule_states_current    value:GAUGE:U:U
+rule_states_total      value:GAUGE:U:U
+rule_evaluations       value:GAUGE:U:U
+rule_bytes             value:GAUGE:U:U