用python实现监控SAP通讯账号状态并自动解锁

    xiaoxiao2022-06-24  210

    SAP PI的通讯账号由于通讯账号比较多并且使用它们的外围更多,有时候会因为某些程序员的粗心,导致某个通讯账号被锁。所以考虑用python实现监控SAP通讯账号状态,自动解锁后通知管理员并在日志中记录。 import smtplib; from email.mime.text import MIMEText; import cx_Oracle #直接cmd用python -m pip install cx_Oracle安装cx_oracle import time

    def send_email(host,username,passwd,send_to,subject,content): msg = MIMEText( content.encode(‘utf8’), _subtype = ‘html’, _charset = ‘utf8’) msg[‘From’] = username msg[‘Subject’] = u’%s’ % subject msg[‘To’] = “,”.join(send_to) try: s = smtplib.SMTP_SSL(host,465) s.login(username, passwd ) s.sendmail(username, send_to,msg.as_string()) s.close() except Exception as e: print ‘Exception: send email failed’, e

    def update_sql(): # 执行存储过程 DBLINK = “ip:端口号/服务名” #服务名可以通过:select value from v$parameter where name like ‘%service_name%’;查到。 DBUSER = “xxx” DBPASS = “xxx” conn = cx_Oracle.connect(DBUSER, DBPASS, DBLINK ) c = conn.cursor() str1= c.var(cx_Oracle.STRING) c.callproc(‘unlockAccountJob’, [str1]) print(str1.getvalue()) if str1.getvalue() is not None: #写日志 f = open(“1.txt”, “a+”) print >> f, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+’ : ‘+ str1.getvalue() f.close() #发邮件 host = ‘xxx’ username = ‘xxx’ passwd = ‘xxx’ to_list = [‘xxx’] subject = ‘PI DEV account unlocked’ content = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+’ : '+ str1.getvalue() send_email(host,username,passwd,to_list,subject,content) c.close() conn.close()

    if _ name __ == ’ _main __’: update_sql()


    最新回复(0)