zeek/testing/btest/spicy/has-analyzer.spicy
Robin Sommer 7dc5a70dc8
Spicy: Add functions to check if Zeek provides an analyzer of a given name.
```
## Checks if there is a Zeek analyzer of a given name.
##
## analyzer: the Zeek-side name of the analyzer to check for
## if_enabled: if true, only checks for analyzers that are enabled
##
## Returns the type of the analyzer if it exists, or ``Undef`` if it does not.
public function has_analyzer(analyzer: string, if_enabled: bool = True): bool &cxxname="zeek::spicy::rt::has_analyzer";

## Differentiates between the types of analyzers Zeek provides.
public type AnalyzerType = enum { Protocol, File, Packet, };

## Returns the type of a Zeek analyzer of a given name.
##
## analyzer: the Zeek-side name of the analyzer to check
## if_enabled: if true, only checks for analyzers that are enabled
##
## Returns the type of the analyzer if it exists, or ``Undef`` if it does not.
public function analyzer_type(analyzer: string, if_enabled: bool = True): AnalyzerType &cxxname="zeek::spicy::rt::analyzer_type";

```

Closes #4481.
2025-07-15 14:22:27 +02:00

32 lines
836 B
Text

# @TEST-REQUIRES: have-spicy
#
# @TEST-EXEC: spicyz -d -o test.hlto %INPUT disable_ssh.cc
# @TEST-EXEC: zeek test.hlto
module Test;
import zeek;
assert zeek::has_analyzer("HTTP");
assert ! zeek::has_analyzer("XXX");
assert zeek::analyzer_type("HTTP") == zeek::AnalyzerType::Protocol;
assert zeek::analyzer_type("SHA1") == zeek::AnalyzerType::File;
assert zeek::analyzer_type("VLAN") == zeek::AnalyzerType::Packet;
assert ! zeek::analyzer_type("XXX");
# Disable the SSH analyzer and check that we pay attention to its state.
public function disable_ssh() &cxxname="disable_ssh";
disable_ssh();
assert ! zeek::has_analyzer("SSH", True);
assert zeek::has_analyzer("SSH", False);
# @TEST-START-FILE disable_ssh.cc
#include "zeek/analyzer/Manager.h"
void disable_ssh() {
zeek::analyzer_mgr->Lookup("SSH")->SetEnabled(false);
}