giip
合作夥伴SES 商機登記
8分鐘閱讀

CQE Repository Script Management Guide

Learn how to manage, execute, and monitor script registration in the CQE (Custom Query Engine) Repository.

🤖 前往 CQE 儲存庫列表 →

📋 Overview

The CQE Repo List provides a centralized repository for your maintenance and diagnostic scripts. You can store scripts once and deploy them across any number of logical servers (LSVR) with custom execution parameters.

🔍 Script Details & Execution

When you click on a script in the list, the detail modal opens with the following capabilities:

1. Script Content

View the full source code of the script. This is read-only in the list view; use the edit feature if modifications are needed.

2. Execution Settings (NEW)

Before registering a script to a server, you can configure how it should run:

  • Active: Toggle whether the script is enabled for the selected servers.
  • Repeat: If enabled, the script will run periodically.
  • Interval (min): Set the frequency for repeated execution (in minutes).
  • Start Date: Specify when the first execution should occur.

3. Server Registration (LSVR Queue Put)

You can select one or more servers from your current project to receive this script.

  • LSVR Selector: Use the checkboxes to choose target servers.
  • Add to Queue: Click this button to register the script with the defined settings for all selected servers.

📊 Script Usage Status

At the bottom of the modal, the Usage Status Table displays all servers currently registered for this specific script.

  • Hostname: The name of the server using the script.
  • Usage: The logical server's defined purpose.
  • Settings: View the active/repeat/interval status for each registration.
  • Last Run: Tracks the last time the script was successfully executed on that machine.

API 參考

有關此功能的 API 詳細規範,請參閱專用指南。

📘 系統管理 API 參考

疑難排解

症狀原因解決
加入佇列後腳本仍未執行執行設定中 啟用 (Active) 處於關閉狀態在詳細視窗中開啟 Active,然後重新加入佇列。
LSVR 選擇器中看不到目標伺服器目前所選專案沒有伺服器,或伺服器屬於其他專案確認已在頂部選擇正確的專案。
重複執行未生效已開啟 重複 (Repeat),但 間隔 (分鐘) 為空將間隔設定為 1 或更大後重新註冊。
使用狀況中的 最後執行 未更新目標伺服器的代理尚未接收到佇列檢查代理連線狀態以及開始時間是否為過去時刻。

🔌 CQE API (自動化)

上述介面操作對應以下 CQE API 動詞(byAK/bySk 分派器)。請求傳送 text(動詞+參數名)、jsondata(值)與 token。

  • CQERepoPut msName msDetail msBody msPer msPrice msType — 將指令碼註冊到儲存庫。

    • text 只攜帶 參數名稱: CQERepoPut msName msDetail msBody msPer msPrice msType
    • jsondata 攜帶實際的值: {"msName":"...","msDetail":"...","msBody":"#!/bin/sh\n...","msPer":0,"msPrice":0,"msType":"sh"}
    • msType 限制為 5 個字元(varchar(5))。像 powershell、expect 或 cmdwin 這類較長的名稱無法儲存 — 請使用下表中的簡短代碼。
    msType目標作業系統代理實際的執行方式
    ps1Windowspowershell.exe(無視窗)
    cmdWindowscmd.exe
    batWindows正規化為 cmd,再以 cmd.exe 執行
    wsfWindowswscript.exe //B //Nologo
    ps1ui / cmduiWindows在桌面工作階段中以可見視窗執行
    shLinuxsh <tempfile>
    pyLinuxpython3 <tempfile>
    ps1Linuxpwsh <tempfile>

    請勿混用作業系統。 Windows 代理只會執行上述的 Windows 類型;其他任何值都會被記錄為 unsupported_script_type 並且 不會執行。Linux 代理則相反 — 它會 把所有未知的類型都交給 sh 執行,因此將 bat/wsf 指令碼指派給 Linux 伺服器時,會在無任何提示的情況下以 sh 執行而失敗。請以你要指派的那些伺服器的作業系統相符的類型來註冊指令碼。

    • 註冊 Linux shell 指令碼: 在 msType 填入 sh,並將完整的 shell 指令碼放入 msBody。Linux 代理會將內容寫入暫存檔並 以 sh 執行,因此 #!/bin/bash shebang 會被忽略。請避免只有 bash 才支援的語法([[ ]]、陣列等),改以 POSIX shell 撰寫;或是在第一行用 exec bash "$0" "$@" 交棒給 bash。

      #!/bin/sh
      # Runs under sh, so use POSIX syntax only. sk/lssn/apiaddrv2 arrive as environment variables.
      curl -s -H "Authorization: Bearer $sk" "$apiaddrv2/health" | jq -r .status
    • 指令碼內容要放在哪裡: 兩種做法都可行。

      • 把完整內容放進 msBody — 主機上不需要預先安裝任何東西,而且在 giip 端的變更會推送到每一台伺服器。建議採用。
      • 把指令碼留在主機上,只去呼叫它 — 適用於本來就需要 jq/curl 等前置條件的主機,或是內容非常長的情況。此時你必須自行追蹤各主機的部署狀態。
      • msBody 為 ntext,因此實際上沒有長度限制(觀測到的最大值: 20,883 個字元)。
  • CQEQueuePut mssn lssngroup csn interval active script_type custom_values repeat startdate auid — 將指令碼指派到伺服器。

    • lssngroup: 逗號分隔的 LSSN 清單(每台伺服器一筆指派)。
    • interval: 分鐘。repeat: 0/1 = 一次性, 2 = 遞迴(每隔 interval 重複)。
    • custom_values: 依伺服器注入的值 → 取代指令碼內容中的 {{CustomVariables}}。
  • CQEQueueGet lssn hostname os op — 代理輪詢以接收下一個指令碼內容。

指令碼內容佔位符: {{CustomVariables}}(每次指派的 custom_values,伺服器端注入)、{{sk}}(代理權杖)、{{lssn}}(代理 LSSN)。

Linux 代理還會把 sk、lssn 與 apiaddrv2 匯出 為環境變數。你可以不用 {{sk}}/{{lssn}} 佔位符,而直接參照 $sk、$lssn 與 $apiaddrv2。

執行限制

Windows 代理Linux 代理
時間限制預設 600 秒;可用 giipAgent.cfg 中的 cqetimeoutsec 變更。超過時指令碼會被終止無
執行方式暫存檔、無視窗行程暫存檔,以 sh 執行
內容長度無限制(ntext)同上

執行間隔: interval 以分鐘為單位。實際的執行頻率由代理的輪詢週期決定 — interval=0 不是 指「沒有排程」,而是指 每一輪輪詢輪替時都重新派送。多個啟用中的佇列會以輪替方式處理,因此在有 N 個佇列時,感受到的間隔會延長到大約 N 倍(於 giipdb docs/30_Specs/SPEC_AND_CHECKLIST.md 中實測)。把間隔設為 1 分鐘並不會讓它執行得比輪詢週期更頻繁。

結果儲存在哪裡: 指令碼的 stdout/stderr 會寫到 執行代理的那台伺服器上的本機記錄檔,而且執行結果也會發佈到 giip — 代理以 kType=lssn、kKey=<lssn>、kFactor=cqeresult 記錄執行結果(標準輸出/標準錯誤、結束碼、耗時、執行時間),摘要記錄仍以 KVSPut(kFactor=giipagent)傳送。在 giip 主控台的 [CQE 執行列表]·[邏輯伺服器執行列表] 頁面按 [輸出] 按鈕即可直接檢視標準輸出與標準錯誤。 查詢範圍限於你所屬的專案(CSN)。詳細規格見 giipdb docs/30_Specs/CQE_SPECIFICATION.md §5.7。

失敗通知: 當 exit_code 非零時,會向該 CSN 的 MQE 通知接收者(電子郵件/Slack)發送自動通知 —— 5 分鐘週期的計時器偵測到失敗記錄後將警報放入佇列,接著發送器會在 2 分鐘內送達。內文包含主機(lssn)、指令碼(mssn)、exit_code、執行時間與連續失敗次數。為防止警報風暴,首次失敗立即發送 1 次,之後需經過冷卻時間(預設 60 分鐘)才會再次通知;收到成功(exit_code=0)時計數重置。若要關閉警報,可依佇列註冊單位將 tMgmtScriptList.failAlertEnabled 設為 0(預設 1)。接收管道於 MQ 通知設定(tMQENotificationConfig)中依 CSN 指定,mncIsActive=0 則停止該 CSN 的所有警報。

完整規格: giipdb docs/30_Specs/CQE_SPECIFICATION.md。


Version: 1.4 Last Updated: 2026-11-19 Source File: giipv3/public/help/cqerepolist.en.md