vieyahn2017 / repos

【已经迁移到goto/javaway】
2 stars 1 forks source link

StackStorm 【事件触发自动化处理框架】 #16

Closed vieyahn2017 closed 7 months ago

vieyahn2017 commented 6 years ago

https://github.com/StackStorm/st2

vieyahn2017 commented 6 years ago

StackStorm是一个强大的自动化平台,结合DevOps和ChatOps,提供可扩展、灵活和健壮的工具链用于应用、服务和工作流的自动化能力。

vieyahn2017 commented 6 years ago

StackStorm的工作步骤大体如下:

  1. StackStorm Sensor感应并触发事件。
  2. Rules Engine对事件进行规则匹配,如果匹配产生任务。
  3. StackStorm Worker执行任务,一般是调用到外部系统。
  4. StackStorm记录审计任务执行的细节。 5.任务执行结果返回给Rules Engine进行进一步处理。
vieyahn2017 commented 6 years ago

可以看出StackStorm是个以事件驱动的系统,为此抽象出一系列概念来分解事件从产生、触发、规则匹配到执行的整个生命周期事件,具体包含核心概论如下:

Sensor感应器

Sensor是一系列的感应器用于接受或者监测事件,当事件发生的时候,Sensor将会通知Trigger提交事件到StackStorm。

Sensor是Python插件实现,只要实现StackStorm定义的接口,然后配置元数据YAML注册到StackStorm

vieyahn2017 commented 6 years ago

Trigger触发器

Trigger代表事件,一般事件是由外部系统产生,比如监控告警,JIRA问题更新等等,另外也有通用的事件触发器,比如定时器或者WebHook。

在StackStorm系统中,Trigger只是String类型的对象,由Sensor注册,用户可以在Sensor插件自定义新的Trigger。

vieyahn2017 commented 6 years ago

Action 动作/任务

Action是事件触发后的处理方式,一般是由外部系统执行,包括:

重启服务 创建云服务 发生邮件 启动Docker容器 制作VM快照

vieyahn2017 commented 6 years ago
Action Runner Description
local-shell-cmd This is the local runner. This runner executes a Linux command on the same host where StackStorm components are running.
local-shell-script This is the local runner. Actions are implemented as scripts. They are executed on the same hosts where StackStorm components are running.
remote-shell-cmd This is a remote runner. This runner executes a Linux command on one or more remote hosts provided by the user.
remote-shell-script This is a remote runner. Actions are implemented as scripts. They run on one or more remote hosts provided by the user.
python-script This is a Python runner. Actions are implemented as Python classes with arun method. They run locally on the same machine where StackStorm components are running.
http-request HTTP client which performs HTTP requests for running HTTP actions.
action-chain This runner supports executing simple linear work-flows.
mistral-v2 Those runners are built on top of the Mistral OpenStack project and support executing complex work-flows.
cloudslang This runner is built on top of the CloudSlang project and supports executing complex workflows.
vieyahn2017 commented 6 years ago

Action可以是通用的执行方式,比如SSH,REST API调用,也能够集成Openstack、Docker/Kubernetes等系统实现。Action Runner是Action的执行环境,StackStorm的内置Action Runner见楼上

vieyahn2017 commented 6 years ago

通过ActionRunner用户可以自定义Action的实现,以下是一个python-script类型的Action用于发送SMS:

---
name:"send_sms"
runner_type:"python-script"
description:"ThissendsanSMSusingtwilio."
enabled:true
entry_point:"send_sms.py"
parameters:
    from_number:
        type:"string"
        description:"Yourtwilio'from'numberinE.164format.Example+14151234567."
        required:true
        position:0
    to_number:
        type:"string"
        description:"RecipientnumberinE.164format.Example+14151234567."
        required:true
        position:1
        secret:true
    body:
        type:"string"
        description:"Bodyofthemessage."
        required:true
        position:2
        default:"Hello{%ifsystem.user%}{{system.user}}{%else%}dude{%endif%}!"
vieyahn2017 commented 6 years ago

Workflow 工作流

Workflow是Action集合,Workflow能够定义Action的执行顺序和条件,组合一系列Action完成复杂的任务。Workflow可以认为是广义意义上的Action。

StackStorm支持2种类型的Workflow:

ActionChain:通过简单的语法定义Action链 Mistral :Openstack的工作流组件,可以同Stackstorm集成,支持复杂的工作流配置。

vieyahn2017 commented 6 years ago

Rule 规则

Rule是映射Trigger到Action(或者Workflow),即当事件触发后,通过Rule定义的标准(Criteria)进行匹配,当匹配成功将执行Action(或者Workflow)。

vieyahn2017 commented 6 years ago

Audit 审计

Audit是用来跟踪和记录Action的执行细节,用于查询定位:

vieyahn2017 commented 6 years ago

内容来自 https://blog.csdn.net/wlhdo71920145/article/details/80338279

vieyahn2017 commented 6 years ago

ChatOps

ChatOps是一种新的DevOps方法,ChatOps是诞生于GitHub的一种基于会话驱动的协作开发方法,过去团队之间的通讯和开发操作是两层皮,导致各种不透明和低效率。ChatOps将开发工具带入开发者聊天室,通过定制的插件和脚本,一个聊天机器人能够执行聊天中输入的各种命令,实现在聊天平台上的团队协作开发自动化,把团队沟通和执行统一整合到一个可视化更高的聊天环境中,“聊着天就把事情办了”。

目前流行的ChatOps聊天机器人主要有Hubot(GitHub的bot,用CoffeeScript和Node.js开发)、Lita(用Ruby开发)和Err(用Python开发)三种,都是开源软件,而且可以整合到开发团队在工作中经常会使用一些聊天工具例如HipChat、Slack、Flowdock和Campfire等。

StackStorm中集成了Hubot作为聊天机器人提供ChatOps,同时提供Action Alias 和Notifications 机制实现更好的体验,如下图所示:

vieyahn2017 commented 6 years ago

利用StackStorm实现故障智能诊断 http://blog.51cto.com/newcourage/2092810

ST2运行机制(简单理解)

Sensor接收或者监听外部Events,触发Triggers,映射到Rules,在Rules中判断是否满足Criteria,满足则运行具体的Workflow

vieyahn2017 commented 5 years ago

StackStorm是什么?

我们参考Stackstorm的官方介绍,StackStorm是一个跨服务和工具的集成和自动化平台。它可以将我们现有的基础架构和应用程序环境绑定到一起,以便能够更轻松将环境自动化。它特别侧重于事件驱动。

(StackStorm is a platform for integration and automation across services and tools. It ties together your existing infrastructure and application environment so you can more easily automate that environment. It has a particular focus on taking actions in response to events————StackStorm官网)

二、StackStorm结合DevOps和ChatOps来提供能力,那么DevOps和ChatOps又分别是什么呢?

1、DevOps:

它是Development和Operations的组合。可以把DevOps看作开发(软件工程)、技术运营和质量保障(QA)三者的交集。DevOps经常被描述为“开发团队与运营团队之间更具协作性、更高效的关系”。

与传统的大规模的、不频繁发布的瀑布式开发模型相比,敏捷开发就是具备了DevOps的能力,更频繁的发布,每次发布包含的变化更少,因此应用程序可以以平滑的速度逐渐成长。 那么StackStorm结合DevOps的能力,一方面可以提高沟通和协作效率,另一方面也可以减少发布周期、降低发布风险等。

2、ChatOps,它是一种新的DevOps方法,诞生于GitHub的一种会话驱动型协作开发的方法,旨在帮助实现自动化。

vieyahn2017 commented 5 years ago

StackStorm是一个跨服务和工具集成和自动化的平台,广泛在业界自动化运维中使用,可很便捷的对接openstack、docker、ansible、saltstack等开源平台和工具。我们利用该开源平台进行GTAC故障场景编排,可以实现自动化分析、提供根因分析报告的能力

编排:

1、先通过Visio等画图工具画出某场景的故障处理流程图

2、再把每个节点的功能,通过创建stackstorm平台中的action(Python脚本)来承载;

3、在设计界面通过拖拉拽方式拖动各个action,组成故障处理工作流workflow;

运行:

找到要执行的workflow,点击“Run”按钮输入参数,直接点击执行,便可以得到包含问题根因分析过程和方案的RCA报告。

vieyahn2017 commented 5 years ago

携程运维自动化平台,上万服务器变更也可以很轻松(转)