Requirements:
1. You do not need to log on to the image of cacti (only available to accessible users), but you need to log on to the image during other operations.
2. Send the Report to the specified email every morning.
Requirement 1:
File:/cacti/graph_image.php
//include("./include/auth.php");include("./include/global.php");
Tea: First remove the verification module, find that the number of Han is missing, and then Auth. in PHP, it is found that this number is in. /include/global. PHP, the problem is solved after the file is loaded.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/43/5C/wKioL1PZ5srDjyggAAH6eX3QQ5E661.jpg "Title =" qq 40731144315.jpg "alt =" wkiol1pz5srdjyggaah6ex3%e661.jpg "/>
Requirement 2: First connect to the email, down the graph, and send the graph to the receiver. Finally, a scheduled task is created.
/code/cacti_report/downimage.py#/usr/bin/pythonimport requests,sysdef DownImage(url,filename): r = requests.get(url) try: ImageFile = open(filename,‘w‘) ImageFile.write(r.content) ImageFile.close() return (0,"Success") except: return (1,"Write imagefile Error!")
/Code/cacti_report/send_cacti.py #! /Usr/bin/ENV Python # Coding: The utf-8import smtplib, timefrom email. mime. multipart import mimemultipartfrom email. mime. text import mimetextfrom email. mime. image import mimeimagefrom downimage import downimageltime = time. strftime ('% Y-% m-% d % H: % m', time. localtime (time. time () sender = 'sender' receiver = 'recipient 'subject = ltime + "\ tnginx status chart, section 100 network traffic diagram, report of the network traffic diagram in section 200 "smtpserver = 'smtp .163.com 'username = '2017 account' pas Sword = '1970 password 'msgroot = mimemultipart ('related ') msgroot ['subobject'] = subjectmsgroot ['to'] = "recipient" nginximage = "/code/cacti_report/image/nginx1.png" t100 = "/code/cacti_report/image/t100.png "T200 ="/code/cacti_report/image/t200.png "# download imageout = downimage (" http://www.cacti.com/cacti/graph_image.php? Action = view & local_graph_id = 6 ", nginximage) out2 = downimage (" http://www.cacti.com/cacti/graph_image.php? Local_graph_id = 51 ", t100) out3 = downimage (" http://www.cacti.com/cacti/graph_image.php? Local_graph_id = 196 ", T200) # define email conentmsgtext = mimetext ('<B> report (yesterday-Today): </B> <br> nginx status chart: <br> <br> network traffic diagram in section 100: <br> <br> network traffic diagram in section 200: <br> <br> ', 'html', 'utf-8 ') # Add email conent to msgrootmsgroot. attach (msgtext) # webxxx load 8 nginx staticmsgimage = mimeimage (open (nginximage, 'rb '). read () msgimage. add_header ('content-id', '<webxxxload8>') msgroot. attach (msgimage) # Switch 100 range trafficmsgimage = mimeimage (open (t100, 'rb '). read () msgimage. add_header ('content-id', '<switch100>') msgroot. attach (msgimage) # Switch 10048 range trafficmsgimage = mimeimage (open (T200, 'rb '). read () msgimage. add_header ('content-id', '<switch200>') msgroot. attach (msgimage) # Send mailsmtp = smtplib. SMTP () SMTP. connect (smtpserver) SMTP. login (username, password) SMTP. sendmail (sender, aggreger, msgroot. as_string () SMTP. quit ()
Scheduled task:
# crontab -l0 8 * * * /code/cacti_report/send_cacti.py
Tea: Remember to use an image folder. At every morning, remember to read the report. The result may be like this.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/43/5E/wKiom1PZ84XhGvRBAAQLuRhVjjY132.jpg "Title =" 2.jpg" alt = "wkiom1pz84xhgvrbaaqlurhvjjy132.jpg"/>
Tea: Do you think it's very tall!