File: commandtest_legacy.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 (36 lines) | stat: -rw-r--r-- 959 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
# Zeekctl test plugin that defines custom commands using the old BroControl
# legacy API.

import BroControl.plugin
import BroControl.cmdresult

class CommandTest(BroControl.plugin.Plugin):
    def __init__(self):
        super(CommandTest, self).__init__(apiversion=1)

    def name(self):
        return "commandtest"

    def pluginVersion(self):
        return 1

    def init(self):
        return True

    def commands(self):
        return [("testcmd", "[<nodes>]", "Test command that expects arguments"),
                ("", "", "Another test command")]

    def cmd_custom(self, cmd, args, cmdout):
        results = BroControl.cmdresult.CmdResult()

        # This is an easy way to force the plugin command to return failure.
        if args == "fail":
            results.ok = False
        else:
            results.ok = True

        cmdout.info("Command name: %s" % cmd)
        cmdout.info("Command args: %s" % args)

        return results