搜索

17.10. 创建 Shellhook 以打印参数

download PDF

创建一个简单的 shellhook 脚本,该脚本在运行远程执行作业时打印"Hello World!"。

前提条件

流程

  1. 修改 /var/lib/foreman-proxy/shellhooks/print_args 脚本,以将参数打印到标准错误输出,以便您可以在 Capsule 日志中看到它们:

    #!/bin/sh
    #
    # Prints all arguments to stderr
    #
    echo "$@" >&2
  2. 在 Satellite Web UI 中,导航到 Administer > Webhooks
  3. Create new
  4. Subscribe to 列表中,选择 Actions Remote Execution Run Host Job Succeeded
  5. 输入 webhook 的名称。
  6. Target URL 字段中,输入您的 Capsule 服务器的 URL,后跟 :9090/shellhook/print_args

    https://capsule.example.com:9090/shellhook/print_args

    请注意,URL 中的 shellhook 是单数的,这与 shellhooks 目录不同。

  7. Template 列表中,选择 Empty Payload
  8. Credentials 选项卡上,选中 Capsule Authorization
  9. Additional 选项卡中,在 Optional HTTP headers 字段中输入以下文本:

    {
        "X-Shellhook-Arg-1": "Hello",
        "X-Shellhook-Arg-2": "World!"
    }
  10. Submit。现在,您已成功创建了一个 shellhook,它会在每次远程执行作业都成功时将"Hello World!"打印到 Capsule 日志。

验证

  1. 在任何主机上运行远程执行作业。您可以使用 时间 作为命令。如需更多信息,请参阅 管理主机 中的 执行远程作业
  2. 验证 shellhook 脚本是否已触发,并将"Hello World!"输出到 Capsule 服务器日志:

    # tail /var/log/foreman-proxy/proxy.log

    您应该在日志末尾找到以下行:

    [I] Started POST /shellhook/print_args
    [I] Finished POST /shellhook/print_args with 200 (0.33 ms)
    [I] [3520] Started task /var/lib/foreman-proxy/shellhooks/print_args\ Hello\ World\!
    [W] [3520] Hello World!
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.