-
-
Save crmaxx/5507603 to your computer and use it in GitHub Desktop.
Zabbix Alert Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import cx_Oracle | |
USER='USER' | |
PASSWORD='PASSWORD' | |
SID='SID' | |
def check_oracle(action): | |
connection = cx_Oracle.connect(USER, PASSWORD, SID) | |
cursor = connection.cursor() | |
if action == 'checkactive': | |
sql="""select to_char(case when inst_cnt > 0 then 1 else 0 end,'FM99999999999999990') retvalue | |
from (select count(*) inst_cnt from v$instance | |
where status = 'OPEN' and logins = 'ALLOWED' and database_status = 'ACTIVE')""" | |
elif action == 'newsms': | |
sql="""select to_char(count(*) ,'FM99999999999999990') retvalue | |
from cms.out_sms | |
where status_id in (0,1) | |
and (expire_date is null or expire_date > sysdate) and (defer_date is null or defer_date < sysdate)""" | |
elif action == 'nomo': | |
sql="""select to_char(count(*) ,'FM99999999999999990') retvalue | |
FROM CMS.IN_SMS WHERE CREATE_DATE>(SYSDATE-1/12)""" | |
elif action == 'badjobs': | |
sql="""select cms_job_monitor() retvalue from dual""" | |
elif action == 'brokerdelay': | |
sql="""select to_char(count(*) ,'FM99999999999999990') retvalue from cms.in_sms where status=6""" | |
elif action == 'smsstatuses': | |
sql="""select status_id, count(*) from cms.out_sms where edit_date > sysdate - 0.125 group by status_id order by status_id""" | |
elif action == 'failedsms': | |
sql="""select to_char(count(*) ,'FM99999999999999990') retvalue | |
from cms.out_sms | |
where status_id in (select id from cms.OUT_SMS_STATUSES where STATUS in ('Failed', 'Rejected', 'Expired')) | |
and create_date > (SYSDATE-1)""" | |
elif action == 'errsms': | |
sql="""select to_char(count(*) ,'FM99999999999999990') retvalue | |
from cms.in_sms | |
where status=2 and error_code=5 and error_description like 'Module name or Short number not found' | |
and create_date>sysdate-0.042""" | |
elif action == 'newbroken': | |
sql="""select to_char(count(*) ,'FM99999999999999990') retvalue from dba_jobs where broken='Y' and last_date > sysdate-30""" | |
elif action == 'jobshang': | |
sql="""SELECT to_char(count(*)+1 ,'FM99999999999999990') retvalue | |
FROM CMS.JOBS_FLAGS F | |
WHERE F.FLAG=1 AND NOT EXISTS( SELECT NULL FROM DBA_JOBS_RUNNING J WHERE J.JOB=F.ID)""" | |
elif action == 'activeusercount': | |
sql="""select to_char(count(*)-1, 'FM99999999999999990') retvalue from v$session where username is not null | |
and status='ACTIVE'""" | |
elif action == 'usercount': | |
sql="""select to_char(count(*)-1, 'FM99999999999999990') retvalue from v$session where username is not null""" | |
elif action == 'dbsize': | |
sql="""SELECT to_char(sum( NVL(a.bytes - NVL(f.bytes, 0), 0)), 'FM99999999999999990') retvalue | |
FROM sys.dba_tablespaces d, | |
(select tablespace_name, sum(bytes) bytes from dba_data_files group by tablespace_name) a, | |
(select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) f | |
WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+) | |
AND NOT (d.extent_management like 'LOCAL' AND d.contents like 'TEMPORARY')""" | |
elif action == 'dbfilesize': | |
sql="""select to_char(sum(bytes), 'FM99999999999999990') retvalue from dba_data_files""" | |
elif action == 'uptime': | |
sql="""select to_char((sysdate-startup_time)*86400, 'FM99999999999999990') retvalue from v$instance""" | |
else: | |
raise ValueError('unknown action %s' % action) | |
cursor.execute(sql) | |
for retvalue in cursor: | |
print retvalue[0] | |
if __name__ == '__main__': | |
""" | |
action = sys.argv[1] | |
""" | |
if len(sys.argv) == 2: | |
check_oracle(action=sys.argv[1]) | |
else: | |
print u"""requires 1 parameter - action | |
\t$ pyzabora.py action | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
# Zabbix SMS Alert script for SMS24 gate. | |
# Use gem 'sms24x7' or gem instal sms24x7 | |
require 'sms24x7' | |
EMAIL='[email protected]' | |
PASSWORD='your_password' | |
if ARGV.count == 2 | |
SmsApi.push_msg_nologin(EMAIL, PASSWORD, ARGV[0], ARGV[1], sender_name: 'Alarm') | |
else | |
puts "Usage: #{$0} recipient_phone sms_text" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
""" | |
Zabbix SMTP Alert script for gmail. | |
""" | |
import sys | |
import smtplib | |
from email.MIMEText import MIMEText | |
from email.Header import Header | |
from email.Utils import formatdate | |
# Mail Account | |
MAIL_ACCOUNT = '[email protected]' | |
MAIL_PASSWORD = 'your mail password' | |
# Sender Name | |
SENDER_NAME = u'Zabbix Alert' | |
# Mail Server | |
SMTP_SERVER = 'smtp.gmail.com' | |
SMTP_PORT = 587 | |
# TLS | |
SMTP_TLS = True | |
def send_mail(recipient, subject, body, encoding='utf-8'): | |
session = None | |
msg = MIMEText(body, 'plain', encoding) | |
msg['Subject'] = Header(subject, encoding) | |
msg['From'] = Header(SENDER_NAME, encoding) | |
msg['To'] = recipient | |
msg['Date'] = formatdate() | |
try: | |
session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT) | |
if SMTP_TLS: | |
session.ehlo() | |
session.starttls() | |
session.ehlo() | |
session.login(MAIL_ACCOUNT, MAIL_PASSWORD) | |
session.sendmail(MAIL_ACCOUNT, recipient, msg.as_string()) | |
except Exception as e: | |
raise e | |
finally: | |
# close session | |
if session: | |
session.quit() | |
if __name__ == '__main__': | |
""" | |
recipient = sys.argv[1] | |
subject = sys.argv[2] | |
body = sys.argv[3] | |
""" | |
if len(sys.argv) == 4: | |
send_mail( | |
recipient=sys.argv[1], | |
subject=sys.argv[2], | |
body=sys.argv[3]) | |
else: | |
print u"""requires 3 parameters (recipient, subject, body) | |
\t$ zabbix-alert-smtp.py recipient subject body | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment