Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nokia/moler/llms.txt

Use this file to discover all available pages before exploring further.

Shared events work across all connection types. They are located in moler.events.shared and do not depend on Unix-specific output formats.

Event list

ClassModuleWhat it detects
Wait4moler.events.shared.wait4Any pattern(s) in connection output
PasswordPromptmoler.events.shared.password_promptCase-insensitive password: prompt
GenericSharedLineEventmoler.events.shared.genericshared_lineevent(abstract base — line-based)
GenericSharedTextualEventmoler.events.shared.genericshared_textualevent(abstract base — textual)

Detailed reference

Wait4moler.events.shared.wait4

The universal event observer. Watches a connection for one or more regex patterns and fires when the configured match condition is met. Wait4prompt (in moler.events.unix) is built on top of this class.
connection
object
required
Moler connection to observe.
detect_patterns
list[str | re.Pattern]
required
List of regex patterns to watch for.
match
str
Match strategy. Options:
  • "any" — fire when any pattern matches a line (default)
  • "all" — fire once all patterns have each matched (order-independent)
  • "sequence" — fire once all patterns have matched in order across consecutive lines
till_occurs_times
int
Number of match events to collect before completing. Default -1 (run indefinitely).
runner
object
Runner used to execute the event.
Result list structure The structure of result depends on the match strategy:
  • "any"result is a flat list of occurrence dicts, one per matching line:
    KeyTypeDescription
    linestrFull line that matched
    matchedstrSubstring matched by the pattern
    groupstupleUnnamed capture groups
    named_groupsdictNamed capture groups
    timedatetimeTimestamp of the match
  • "all" / "sequence"result is a list of match-sets. Each match-set is itself a list containing one occurrence dict per pattern, in the order the patterns were satisfied.
from moler.events.shared.wait4 import Wait4

event = Wait4(
    connection=conn,
    detect_patterns=[r'number (\d5)', r'(?P<LINE>Line\d+).*number 20'],
    match='any',
    till_occurs_times=3,
)
result = event()
# result is a flat list of up to 3 matching-line dicts
for item in result:
    print(item['line'], item['named_groups'])

Match modes explained

ModeBehaviourResult shape
anyEach line is checked against all patterns independently; fires on every individual match[{match_dict}, ...]
allCollects matches for each pattern; fires once every pattern has been seen (in any order)[[{p0_dict}, {p1_dict}], ...]
sequenceLike all, but pattern[N+1] is only considered after pattern[N] has already matched[[{p0_dict}, {p1_dict}], ...]
For match='sequence', if pattern[0] matches but pattern[1] never follows, the event will not fire (unless till_occurs_times would be satisfied by a later re-match of pattern[0] followed by pattern[1]).

PasswordPromptmoler.events.shared.password_prompt

Fires whenever a case-insensitive password: prompt appears on the connection. Useful for detecting interactive credential requests during login flows on any device type.
connection
object
required
Moler connection to observe.
till_occurs_times
int
Number of occurrences to collect. Default -1.
Detection pattern: r'password:' (case-insensitive) Result list item keys
KeyTypeDescription
timedatetimeTimestamp when the prompt was detected
linestrThe line containing password:
from moler.events.shared.password_prompt import PasswordPrompt

event = PasswordPrompt(connection=conn, till_occurs_times=1)
result = event()
print(result[0]['line'])  # 'Password:'
print(result[0]['time'])  # datetime.datetime(...)

Base classes

GenericSharedLineEventmoler.events.shared.genericshared_lineevent

Base for events that match on complete lines using a list of detect_patterns. Subclass this when you need a simple line-pattern event that works on any connection type.
from moler.events.shared.genericshared_lineevent import GenericSharedLineEvent

class MyEvent(GenericSharedLineEvent):
    def __init__(self, connection, till_occurs_times=-1, runner=None):
        super().__init__(
            connection=connection,
            runner=runner,
            till_occurs_times=till_occurs_times,
            detect_patterns=[r'my pattern (?P<VALUE>\d+)'],
            match='any',
        )

GenericSharedTextualEventmoler.events.shared.genericshared_textualevent

Base for events that require custom on_new_line() parsing logic rather than simple pattern lists. Subclass this when the event needs to aggregate data across multiple lines (like LastLogin).

Combining events with commands

A common pattern is to start a shared event before running a command so it can observe the output in parallel:
from moler.events.shared.wait4 import Wait4
from moler.cmd.unix.ping import Ping

# Monitor for packet loss while running ping
loss_event = Wait4(
    connection=conn,
    detect_patterns=[r'(?P<LOSS>\d+)% packet loss'],
    match='any',
    till_occurs_times=1,
)
loss_event.start()

# Run ping command
ping = Ping(connection=conn, destination='8.8.8.8', options='-c 10')
ping_result = ping()

loss_event.cancel()

# Both the command result and any event matches are available
print("Final loss:", ping_result['packet_loss'])

Build docs developers (and LLMs) love