« Previous 1 2 3
Manage and automate networks
Perfect Storm
Automation with Rules
Rules play a central role in StackStorm because they determine which actions are triggered by events. A rule in StackStorm waits for the activation of a specific trigger. As soon as this happens, the rule checks defined criteria and executes an associated action. If an event (trigger) occurs and the conditions are met, an action is triggered.
A rule begins with the description and definition of a trigger that specifies the event you want to monitor. One frequently used example is the Interval Timer, a native trigger in StackStorm that fires up at regular intervals (e.g., every 60 seconds). With this trigger, the rule can then execute an action, such as starting a workflow or executing a local command.
Rules are very flexible because they can either start a single action or a complex workflow with multiple actions. This ability makes them powerful tools for triggering automations on almost any event. Now save the configuration file,
hostname: "dc1.joos.int" ip: "10.0.1.230" username: "Administrator" password: "YourPassword" base_dn: "DC=joos,DC=int" use_ssl: true port: 636 default_ad_server: "10.0.1.230"
as /opt/stackstorm/configs/activedirectory.yaml and reload the configuration to make the changes effective:
st2ctl reload --register-configs
Now you can create a rule that uses a specific Active Directory pack action to check whether the domain controller is reachable. The activedirectory.get_dc_status action queries the status of the domain controller to do this. The YAML file in Listing 5 defines a rule that checks the status of the domain controller every 60 seconds and mails a notification if the domain controller cannot be reached. You will want to save this file as dc_status_check_rule.yaml in the StackStorm directory and then apply the rule:
Listing 5
DC Monitoring Rule
name: "dc_status_check_rule"
description: "Monitors the status of the domain controller every 60 seconds"
enabled: true
trigger:
type: "core.interval_timer"
parameters:
unit: "seconds"
delta: 60
action:
ref: "activedirectory.get_dc_status"
parameters:
host: "10.0.1.230"
use_ssl: true
username: "Administrator"
password: "YourPassword"
result_handler:
when: "result == 'offline'"
action:
ref: "core.sendmail"
parameters:
to: "admin@joos.int"
subject: "Warning: Domain controller dc1.joos.int not reachable"
body: | The domain controller dc1.joos.int with the IP address 10.0.1.230 is not reachable. Please check the status of the server.
st2 rule apply /opt/stackstorm/packs/activedirectory/rules/dc_status_check_ rule.yaml
Make sure the configuration for sending email is set up correctly by editing the /opt/stackstorm/configs/mail.yaml file:
smtp_host: "smtp.joos.int" smtp_port: 587 from: "stackstorm@joos.int" smtp_user: "stackstorm" smtp_password: "yourSMTPpassword" use_ssl: false use_tls: true
After you have customized the email configuration, reload it:
st2ctl reload --register-configs
From now on, StackStorm checks the status of the domain controller once a minute with the activedirectory.get_dc_status action. If the domain controller (DC) is offline, StackStorm automatically sends email to the admin.
Conclusions
StackStorm can significantly improve the management and automation of networks. The platform lets you automate recurring tasks and respond to network events in real time. Thanks to the modular architecture, you can orchestrate complex processes dynamically. The numerous integration options provided by packs offer a flexible and expandable approach.
Infos
- StackStorm: https://stackstorm.com/
- Documentation for actions: https://docs.stackstorm.com/actions.html
- StackStorm Exchange: https://exchange.stackstorm.org/
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
