SKILL.md
readonly只读
name
devops-automation
description
DevOps与IT运维自动化——CI/CD、监控、事件管理和基础设施工作流
version
1.0.0
DevOps自动化
自动化DevOps工作流,包括CI/CD流水线、监控、事件管理和基础设施运维。基于n8n的IT运维工作流模板。
概述
本技能涵盖:
- CI/CD流水线自动化
- 监控与告警
- 事件管理
- 基础设施自动化
- 部署工作流
CI/CD自动化
GitHub Actions集成
workflow: "GitHub CI/CD通知"
triggers:
- github_push
- github_pull_request
- github_workflow_run
on_push:
action:
- trigger_ci: if_main_branch
- notify_slack:
channel: "#deployments"
message: |
📦 *新推送至{branch}*
提交:`{commit_sha_short}`
作者:{author}
消息:{commit_message}
[查看差异]({compare_url})
on_pr_opened:
action:
- notify_slack:
channel: "#code-review"
message: |
🔀 *新拉取请求*
标题:{pr_title}
作者:{author}
分支:{head} → {base}
[审查PR]({pr_url})
- assign_reviewers: based_on_codeowners
- run_ci_checks
on_workflow_complete:
action:
- notify_slack:
message: |
{status_emoji} *构建{status}*
工作流:{workflow_name}
分支:{branch}
耗时:{duration}
{if_failed: [查看日志]({logs_url})}
部署流水线
deployment_pipeline:
stages:
build:
trigger: push_to_main
steps:
- checkout_code
- install_dependencies
- run_tests
- build_artifact
- push_to_registry
staging:
trigger: build_success
steps:
- deploy_to_staging
- run_integration_tests
- notify_qa
production:
trigger: manual_approval
steps:
- create_backup
- deploy_to_production
- run_smoke_tests
- notify_team
rollback:
trigger: deployment_failed OR manual
steps:
- revert_to_previous
- notify_team
- create_incident
监控与告警
告警路由
alert_routing:
sources:
- prometheus
- datadog
- cloudwatch
- new_relic
severity_levels:
critical:
response_time: 5_minutes
channels: [pagerduty, slack_urgent, sms]
escalation: immediate
high:
response_time: 15_minutes
channels: [slack_alerts, email]
escalation: after_15_minutes
medium:
response_time: 1_hour
channels: [slack_alerts]
low:
response_time: 24_hours
channels: [slack_logging]
routing_rules:
- if: service == "payments"
team: payments_oncall
severity_boost: +1
- if: service == "auth"
team: security_oncall
- default:
team: platform_oncall
告警模板
alert_templates:
infrastructure:
cpu_high:
title: "🔥 CPU使用率高"
body: |
服务器:{host}
CPU:{cpu_percent}%
持续时间:{duration}
阈值:{threshold}%
[查看仪表盘]({grafana_url})
memory_critical:
title: "💾 内存严重不足"
body: |
服务器:{host}
内存:{memory_percent}%
可用:{available_mb}MB
[SSH连接服务器]({ssh_link})
disk_full:
title: "💿 磁盘空间严重不足"
body: |
服务器:{host}
磁盘:{disk_percent}%
可用:{available_gb}GB
建议:清理日志或扩展卷
application:
error_spike:
title: "📈 错误率飙升"
body: |
服务:{service}
错误率:{error_rate}%
正常值:{baseline}%
主要错误:
{top_errors}
latency_high:
title: "🐢 高延迟"
body: |
服务:{service}
P99延迟:{p99_ms}ms
阈值:{threshold_ms}ms
事件管理
事件工作流
incident_workflow:
detection:
sources: [monitoring, user_report, automated_check]
triage:
auto_severity:
- if: affects_payments
severity: critical
- if: affects_auth
severity: critical
- if: affects_api AND error_rate > 10%
severity: high
response:
critical:
- create_incident_channel: "#inc-{timestamp}"
- page_oncall: immediately
- notify_stakeholders: [engineering_lead, product]
- start_war_room: zoom_link
- create_status_page: incident
high:
- create_incident_channel
- notify_oncall: slack
- create_ticket: jira
communication:
internal:
frequency: every_30_minutes
channel: incident_channel
template: |
📊 *事件更新*
状态:{status}
影响:{impact}
下次更新:{next_update_time}
当前操作:
{action_items}
external:
channel: status_page
template: customer_facing_update
resolution:
steps:
- confirm_resolution
- update_status_page: resolved
- notify_stakeholders
- schedule_postmortem
- close_incident_channel: after_24h
事后复盘模板
postmortem_template:
sections:
summary:
- incident_title
- duration
- severity
- impact
timeline:
format: |
| 时间 | 事件 |
|------|------|
| {time} | {event} |
root_cause:
- what_happened
- why_it_happened
- contributing_factors
impact:
- users_affected
- revenue_impact
- sla_breach
resolution:
- how_it_was_fixed
- time_to_detect
- time_to_resolve
action_items:
format: |
| 操作 | 负责人 | 截止日期 | 状态 |
|------|--------|----------|------|
lessons_learned:
- what_went_well
- what_went_poorly
- lucky_breaks
基础设施自动化
服务器配置
provisioning_workflow:
trigger: jira_ticket OR slack_request
steps:
1. validate_request:
check: [budget_approval, security_review]
2. create_infrastructure:
terraform:
- vpc
- security_groups
- ec2_instances
- load_balancer
3. configure_server:
ansible:
- base_configuration
- security_hardening
- monitoring_agent
- application_setup
4. validate:
- health_check
- security_scan
- performance_baseline
5. notify:
slack: "✅ 服务器{hostname}已就绪"
include: [ssh_access, dashboard_link]
计划维护
maintenance_automation:
tasks:
certificate_renewal:
schedule: "到期前30天"
action:
- request_new_cert: letsencrypt
- deploy_cert
- verify_ssl
- notify: if_failure
security_patching:
schedule: "每周"
action:
- check_updates
- if_critical: immediate_patch
- else: schedule_maintenance_window
log_rotation:
schedule: "每天"
action:
- rotate_logs
- compress_old
- upload_to_s3
- delete_local: older_than_7_days
backup_verification:
schedule: "每周"
action:
- restore_to_test_env
- run_integrity_checks
- report_status
Kubernetes自动化
K8s工作流
kubernetes_automation:
deployment:
trigger: docker_image_pushed
steps:
- update_manifest: with_new_image_tag
- apply_to_staging
- run_tests
- if_success: apply_to_production
scaling:
trigger: metric_threshold
rules:
- if: cpu > 80%
action: scale_up
max_replicas: 10
- if: cpu < 20%
action: scale_down
min_replicas: 2
rollback:
trigger: health_check_failed
action:
- kubectl_rollout_undo
- notify_team
- create_incident
输出示例
请求:"设置GitHub Actions的部署通知"
输出:
# GitHub Actions部署通知
## n8n工作流
```yaml
trigger: GitHub Webhook
events: [workflow_run]
通知模板
构建开始:
🚀 *部署已开始*
分支:main
提交:abc1234
作者:@developer
触发方式:推送
[查看工作流](https://github.com/...)
构建成功:
✅ *部署成功*
环境:生产
耗时:3分42秒
版本:v1.2.3
变更:
• 功能X
• 错误修复Y
[查看部署](https://app.example.com)
构建失败:
❌ *部署失败*
阶段:测试
错误:npm test失败
[查看日志](https://github.com/...)
[重试](https://github.com/...)
Slack集成
channel: "#deployments"
mention_on_failure: "@oncall"
thread_replies: true
---
*DevOps自动化技能——Claude Office技能的一部分*






