Monday, February 20, 2023

git_

 -bash-4.2$ cat git_post_automation.py

#!/usr/bin/python3

from subprocess import Popen,PIPE

from email.mime.multipart import MIMEMultipart

import smtplib

from datetime import datetime

from email.mime.base import MIMEBase

from email import encoders

from email.mime.text import MIMEText

import sys

import os


node = ""

server_name = ""

try :

    env=sys.argv[1]

    if env.lower() == "dr":

        print("DR")

        node = "[sps_eap_cust360_hdr@hnr01n02-d]$"

        server_name = "sps_eap_cust360_hdr"

    elif env.lower() == "itg":

        print("itg")

        node = "[srvc_nextgen_hitg@hnr02n04~]$"

        server_name = "srvc_nextgen_hitg"

    elif env.lower() == "prod":

        print("prod")

        node = "[srvc_eap_cust360_hpro@hnr04n01~]$"

        server_name = "srvc_eap_cust360_hpro"

    else:

        print("please enter the python git_post_auotation.py <itg/dr/prod> ")

except :

    print("please enter the python git_post_auotation.py <itg/dr/prod> ")

print(node)


sender = "shravan.narisetty@hpe.com"  # the sender's email address 'hpe-it-eap-cp360_support@hpe.com'

receiver = "shravan.narisetty@hpe.com" # the recipient's email address 'hpe-it-eap-cp360_support@hpe.com'

msg = MIMEMultipart('alternative')

msg['From'] = sender

msg['To'] = receiver


text = "Hi Team,<br/><br/>Please find the status of daily job logs as of " + datetime.today().strftime(


            "%d-%b-%Y %H:%M:%S GMT") + " <br/>"

html = """

        <html>

            <head>

                <style type="text/css" media="screen"> th, td {padding: 1px;} </style>

            </head>

            <body"> """

##########################################################################

############check jar file ###############################################

##########################################################################

html = html + """<p>Taking screenshot JAR File</p>"""

dr_jar="hadoop fs -ls /user/"+server_name+"/cp360/oozie/hpe-eap-oozie-cp360/jar_main/"

t1 = os.system(dr_jar+"|grep -i EAP_[CP]360-1.0.jar>a.txt")

html = html + """<p style="background-color:black;color:white">""" + node + dr_jar + """</br> """

with open("a.txt") as file1:

    for w_f in file1:

        print(w_f)

        html =html+ w_f + """</br> """+"""</p1>"""


##########################################################################

############check oozie file ###############################################

##########################################################################

html = html + """<p>Taking screenshot oozie customer side</p>"""

dr_oozie_cust="hadoop fs -ls /user/"+server_name+"/cp360/oozie/hpe-eap-oozie-cp360/customer/"

t1 = os.system(dr_oozie_cust+">a.txt")

html = html + """<p style="background-color:black;color:white">""" + node + dr_oozie_cust + """</br> """

with open("a.txt") as file1:

    for w_f in file1:

        print(w_f)

        html =html+ w_f +"""</br> """+ """</p1>"""


##########################################################################

############check oozie partner side###############################################

##########################################################################

html = html + """<p>Taking screenshot partner side</p>"""

dr="[sps_eap_cust360_hdr@hnr01n02-d]$"

dr_oozie_prnt="hadoop fs -ls /user/"+server_name+"/cp360/oozie/hpe-eap-oozie-cp360/partner"

t1 = os.system(dr_oozie_prnt+">a.txt")

html = html + """<p style="background-color:black;color:white">""" + node + dr_oozie_prnt + """</br> """

with open("a.txt") as file1:

    for w_f in file1:

        print(w_f)

        html =html+ w_f +"""</br> """+ """</p1>"""


##########################################################################

############check properties file ###############################################

##########################################################################

html = html + """<p>Taking screenshot properties side</p>"""

dr_properties="hadoop fs -ls /user/"+server_name+"/cp360/properties/"

t1 = os.system(dr_properties+">a.txt")

html = html + """<p style="background-color:black;color:white">""" + node + dr_properties + """</br> """

with open("a.txt") as file1:

    for w_f in file1:

        print(w_f)

        html =html+ w_f +"""</br> """+ """</p1>"""

##########################################################################

############check python script ###############################################

##########################################################################

html = html + """<p>Taking screenshot python script</p>"""

dr_python="ls -ltr /home/"+server_name+"/cp360/python_scripts"

t1 = os.system(dr_python+">a.txt")

html = html + """<p style="background-color:black;color:white">""" + node + dr_python + """</br> """

with open("a.txt") as file1:

    for w_f in file1:

        print(w_f)

        html =html+ w_f +"""</br> """+ """</p1>"""


##########################################################################

############check Shell shell script ###############################################

##########################################################################

html = html + """<p>Taking screenshot shell script</p>"""

dr_shell="ls -ltr /home/"+server_name+"/cp360/shell_scripts"

t1 = os.system(dr_shell+">a.txt")

html = html + """<p style="background-color:black;color:white">""" + node + dr_shell + """</br> """

with open("a.txt") as file1:

    for w_f in file1:

        print(w_f)

        html =html+ w_f +"""</br> """+ """</p1>"""


##########################################################################

############check Shell properties script ###############################################

##########################################################################

html = html + """<p>Taking screenshot shell script script</p>"""

dr_prop="ls -ltr /home/"+server_name+"/cp360/properties"

t1 = os.system(dr_prop+">a.txt")

html = html + """<p style="background-color:black;color:white">""" + node + dr_prop + """</br> """

with open("a.txt") as file1:

    for w_f in file1:

        print(w_f)

        html =html+ w_f +"""</br> """+ """</p1>"""



html =html+"""   </body>

                 <p><font face="Calibri"><br/>Thank You,<br/>CP360 Support.</font></p>

         </html>"""

msg['Subject'] = "CP360 - Pre $ Post Screenslot in "+ env.upper() +" "+ datetime.today().strftime('%d-%m-%Y %H:%M:%S GMT')

part1 = MIMEText(html, 'html')

msg.attach(part1)

s = smtplib.SMTP('smtp3.hpe.com')

s.sendmail(sender, receiver.split(","), msg.as_string())

s.quit()


No comments:

Post a Comment