File: lb_custom.py

package info (click to toggle)
zeekctl 2.2.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,544 kB
  • sloc: python: 5,639; sh: 1,374; makefile: 71; awk: 24
file content (39 lines) | stat: -rw-r--r-- 1,260 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# This plugin introduces a new load balancing method "custom", which does
# nothing by default.  To support packet source plugins, it allows to set a
# prefix and suffix for the interface name.  For example, add the following
# line to zeekctl.cfg to enable the AF_PACKET plugin:
# lb_custom.InterfacePrefix = af_packet::

import ZeekControl.plugin

class LBCustom(ZeekControl.plugin.Plugin):
    def __init__(self):
        super(LBCustom, self).__init__(apiversion=1)

    def name(self):
        return "lb_custom"

    def pluginVersion(self):
        return 1

    def init(self):
        useplugin = False

        for nn in self.nodes():
            if nn.type != "worker" or nn.lb_method != "custom":
                continue

            useplugin = True

            prefix = self.getOption("InterfacePrefix")
            suffix = self.getOption("InterfaceSuffix")
            nn.interface = "%s%s%s" % (prefix, nn.interface, suffix)

        return useplugin

    def options(self):
        custom_options = [
          ("InterfacePrefix", "string", "", "Prefix to prepend to the configured interface name."),
          ("InterfaceSuffix", "string", "", "Suffix to append to the configured interface name."),
        ]
        return custom_options