Nagios server alert text message script

Source: Internet
Author: User
Tags perl script

I once wrote a Perl script for my friend Tian Yi, which is mainly used for alarm of Nagios server faults. It is very simple and mainly uses the lwp: simple module to request the SMS Service API.

#! /Usr/bin/perl-W <br/> use strict; </P> <p> Use lwp: simple; <br/> Use URI: escape; <br/> Use Digest: MD5; </P> <p> my ($ mobile, $ content) = @ argv; # Get Params from command line <br/> my $ log_control = 1; # a switch of log <br/> my $ username = 'sery '; # Your SMS service username <br/> my $ Password = 'abcdefg'; # Your SMS service password <br/> my $ key = 'ysdbyhd6t '; # Your SMS service key <br/> my $ souce_conten T = substr ($ mobile, 0, 8 ). substr ($ mobile,-10, 10 ). $ key; </P> <p> my $ MD5 = Digest: MD5-> New; <br/> $ MD5-> Add ($ souce_content ); <br/> my $ keyword = UC ($ MD5-> hexdigest); </P> <p> my $ result = get "http://http.asp.sh.cn/MT.do? Username = $ username & <br/> Password = $ password & mobile = $ mobile & content = $ content & keyword = $ keyword "; </P> <p> if ($ log_control) {<br/> my $ FH; <br/> open ($ FH, '>/var/log/SMS. log ') or die "can't open log: $! "; # Make sure have permission <br/> Print $ FH join ('', time, $ result, "/N"); <br/> close $ FH; <br/>} 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.