Monitoring your whole infrastructure is very essential specially in IT infrastructures. I recently learn creating and writing scripts for monitoring like this. I will share you how I make telegram and email notifications script. This script sends an telegram and email notification whenever a problem in the infrastructure occurs.
What is Zabbix
Zabbix is an open source software that monitors numerous parameters of a network and the health and integrity of servers, virtual machines, applications, services, databases, websites, the cloud and more. Zabbix uses a flexible notification mechanism that allows users to configure email-based alerts for virtually any event. This allows a fast reaction to server problems. Zabbix offers excellent reporting and data visualization features based on the stored data. This makes Zabbix ideal for capacity planning.
Telegram Notification Script
Log in to your Zabbix proxy/server via SSH and go to "externalscripts" directory.
cd /usr/lib/zabbix/externalscripts
Create the script for Telegram bot. Set up your telegram bot here.
sudo vim telegram-notif.sh
Paste the script below
#!/bin/bash # Telegram Bot API Token BOT_TOKEN="YOUR_BOT_TOKEN" # Telegram Chat ID CHAT_ID="YOUR_TELEGRAM_CHAT_ID" # Message to be sent MESSAGE="$1" # Sends the telegram message curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" -d "chat_id=$CHAT_ID&text=$MESSAGE"
Save your script.
:wq
Convert it to an executable file
chmod +x telegram-notif.sh
Email Notification Script
In the same directory, create a python file.
sudo vim email-notif.py
Paste this code. This code requires an app password from your gmail account. Create your app password here.
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import sys # Get the alert message from command-line arguments alert_message = sys.argv[1] # Email account credentials gmail_user = 'YOUR_EMAIL_ADDRESS' gmail_password = 'YOUR_APP_PASSWORD' # Use your App Password here # Create the message msg = MIMEMultipart() msg['From'] = gmail_user msg['To'] = 'YOUR_RECIPIENT_EMAIL_ADDRESS' # Recipient's email address msg['Subject'] = 'Alert Message Subject' # Subject of the email message = alert_message msg.attach(MIMEText(message, 'plain')) # Attempt to send the email try: server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.ehlo() server.login(gmail_user, gmail_password) server.send_message(msg) server.close() print('Email sent!') except Exception as e: print('Failed to send email:', e)
Don't forget to save and make this an executable file
:wq
chmod +x email-notif.py
This script can be integrated in Zabbix to notify issues that needs to be addressed as quickly as possible.
In some instances, running a python script in a server requires root permissions(sudo). To allow Zabbix run the python script with sudo, you must edit the visudo.
sudo visudo
Find the "User privilege specification" and paste this line of code under it.
zabbix ALL=(ALL) NOPASSWD: /usr/lib/zabbix/externalscripts/your_script.py
So it will look like this
# User privilege specification root ALL=(ALL:ALL) ALL zabbix ALL=(ALL) NOPASSWD: /usr/bin/python3 zabbix ALL=(ALL) NOPASSWD: /usr/lib/zabbix/externalscripts/your_script.py
Thanks for reading!
以上がZabbix 用の電報および電子メール通知スクリプトの作成の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

numpyarraysarasarebetterfornumeroperations andmulti-dimensionaldata、whilethearraymoduleissuitable forbasic、1)numpyexcelsinperformance and forlargedatasentassandcomplexoperations.2)thearraymuremememory-effictientivearientfa

NumPyArraySareBetterforHeavyNumericalComputing、whilethearrayarayismoreSuitableformemory-constrainedprojectswithsimpledatatypes.1)numpyarraysofferarays andatiledance andpeperancedatasandatassandcomplexoperations.2)thearraymoduleisuleiseightweightandmemememe-ef

ctypesallowsinging andmanipulatingc-stylearraysinpython.1)usectypestointerfacewithclibrariesforperformance.2)createc-stylearraysfornumericalcomputations.3)passarraystocfunctions foreffientientoperations.how、how、becuutiousmorymanagemation、performanceo

Inpython、「リスト」は、「リスト」、自由主義的なもの、samememory効率が高く、均質な偶然の瞬間の想起された「アレイ」の「アレイ」の「アレイ」の均質な偶発的な想起されたものです

pythonlistsandarraysaraybothmutable.1)listsareflexibleandsupportheTeterdatabutarlessmemory-efficient.2)Arraysaremorememory-efficientiant forhomogeneousdative、ressivelessatile、ressing comerttytytypecodeusageodoavoiderorors。

PythonとCにはそれぞれ独自の利点があり、選択はプロジェクトの要件に基づいている必要があります。 1)Pythonは、簡潔な構文と動的タイピングのため、迅速な開発とデータ処理に適しています。 2)Cは、静的なタイピングと手動メモリ管理により、高性能およびシステムプログラミングに適しています。

PythonまたはCの選択は、プロジェクトの要件に依存します。1)迅速な開発、データ処理、およびプロトタイプ設計が必要な場合は、Pythonを選択します。 2)高性能、低レイテンシ、および緊密なハードウェアコントロールが必要な場合は、Cを選択します。

毎日2時間のPython学習を投資することで、プログラミングスキルを効果的に改善できます。 1.新しい知識を学ぶ:ドキュメントを読むか、チュートリアルを見る。 2。練習:コードと完全な演習を書きます。 3。レビュー:学んだコンテンツを統合します。 4。プロジェクトの実践:実際のプロジェクトで学んだことを適用します。このような構造化された学習計画は、Pythonを体系的にマスターし、キャリア目標を達成するのに役立ちます。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

Dreamweaver Mac版
ビジュアル Web 開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ホットトピック









