Oxidized 配置文件比对
Oxidized 使用 rugged/libgit2 接口, 通过 git diff 来比较配置文件差异
Oxidized 配置文件
output:
default: git
git:
user: Oxidized
email: o@example.com
repo: "/home/ubuntu/.config/oxidized/git-repos/default.git"
重启 Oxidized 服务
systemctl restart oxidized.service
~/.config/oxidized/ 目录下会生成一个git-repos目录
Oxidized Web 第一个备份的配置文件为 Version 1
修改网络设备文件,更改 Ethernet1/0/23 接口描述
[MT-sw-Ethernet1/0/23]dis this
#
interface Ethernet1/0/23
description To-chukousw
port link-type trunk
undo port trunk permit vlan 1
port trunk permit vlan 99 300
#
return
[MT-sw-Ethernet1/0/23]description To-chukousw
[MT-sw-Ethernet1/0/23]dis this
#
interface Ethernet1/0/23
description To-chukousw1
port link-type trunk
undo port trunk permit vlan 1
port trunk permit vlan 99 300
#
return
[MT-sw-Ethernet1/0/23]quit
Oxidized Web 发生改变的备份的配置文件为 Version 2
update 网络配置文件后比对配置文件 粉色为删除的命令行 绿色为增加的命令行
Oxidized 邮件通知
Oxidized 提供一个扩展的邮件脚本 oxidized-report-git-commits,在配置备份成功,失败,变更和所有节点备份完成发送邮件通知。
查找oxidized-report-git-commits 脚本
ubuntu@ecv-node1:/$ sudo find / -name oxidized-report-git-commits
/var/lib/gems/2.7.0/gems/oxidized-0.28.0/extra/oxidized-report-git-commits
官方 hooks 例子
hooks:
name_for_example_hook1:
type: exec
events: [node_success]
cmd: 'echo "Node success $OX_NODE_NAME" >> /tmp/ox_node_success.log'
name_for_example_hook2:
type: exec
events: [post_store, node_fail]
cmd: 'echo "Doing long running stuff for $OX_NODE_NAME" >> /tmp/ox_node_stuff.log; sleep 60'
async: true
timeout: 120
hooks 参数介绍
timeout 命令执行的硬超时(以秒为单位)。超时后,SIGTERM将被发送到子进程。默认:60
async 以异步方式执行命令。默认情况下,主线程将等待钩子命令执行完成。true对于长时间运行的命令,请将其设置为,这样就不会阻止节点配置请求。默认:false
cmd 命令运行
event 类型
node_success 在从节点成功提取配置时触发,并且在存储配置之前触发。
node_fail 在retries失败的节点拉动数量后触发。
post_store 在存储节点配置后触发(仅在配置更改后才执行)。
nodes_done 在获取所有节点后触发。
配置heirloom-mailx邮件
添加软件源
sudo vim /etc/apt/sources.list
deb http://cz.archive.ubuntu.com/ubuntu xenial main universe
安装heirloom-mailx
sudo apt-get update
sudo apt install heirloom-mailx
配置发送邮件账户密码
sudo vim /etc/s-nail.rc
# 指定邮箱
set from=******@qq.com
# 邮箱协议
set smtp="smtp.qq.com"
# 邮箱账号
set smtp-auth-user="******@qq.com"
# 邮箱授权码,QQ邮箱后台里面去授权
set smtp-auth-password=******"
# 登陆方式
set smtp-auth=login
发送测试邮件
echo "test" | s-nail -s "this is a test mail" ******@126.com
Oxidized hooks 配置
hooks:
email_output:
type: exec
events: [post_store, node_fail]
cmd: '/var/lib/gems/2.7.0/gems/oxidized-0.28.0/extra/oxidized-report-git-commits | s-nail -s "Oxidized updates for ${OX_NODE_NAME}" songhongpeng@126.com'
async: true
timeout: 120
重启 Oxidized 服务
sudo systemctl restart oxidized
手动触发备份
查看邮件