記事

ログ監視とLINE通知で社内監視を自動化する方法

ログ監視とLINE通知で社内監視を自動化する方法

サーバやアプリの異常を早期検知するには、ログ監視の自動化が有効です。 PythonやPowerShellで定期チェックし、異常をLINE通知すれば即対応できます。

1. Python例:ログ監視+LINE通知


import requests, time

while True:
    with open("system.log") as f:
        lines = f.readlines()
        if "ERROR" in lines[-1]:
            requests.post(
                "https://notify-api.line.me/api/notify",
                headers={"Authorization": "Bearer xxxxxx"},
                data={"message": "エラー検出: " + lines[-1]}
            )
    time.sleep(60)

2. PowerShell例


if (Select-String -Path "system.log" -Pattern "ERROR") {
  Invoke-RestMethod -Uri "https://notify-api.line.me/api/notify" `
  -Headers @{Authorization="Bearer xxxxxx"} `
  -Body @{message="Error detected"}
}

まとめ

監視作業を自動化すれば、トラブル発生時も即時対応が可能です。 → 監視ツール開発サービス

関連記事

カテゴリー

ページ上部へ戻る