-
Notifications
You must be signed in to change notification settings - Fork 0
/
hcid_disableuser_v0.1
executable file
·94 lines (73 loc) · 3.36 KB
/
hcid_disableuser_v0.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
import csv
import pandas as pd
import numpy as np
import time
import sys
import random
import scpclient
import md5
import os
import socket
import smtplib
from pandas import DataFrame
from sqlalchemy import create_engine
# Golbal Variable
datenow=(time.strftime("%Y-%m-%d"))
#filename=sys.argv[1]
ADEX_FILE='/opt/output/ad_disable-'+datenow+'.csv'
ZM_FILE='/opt/output/zimbra_disable-'+datenow+'.csv'
IMPORT_DB='/opt/output/importdb_disable-'+datenow+'.csv'
#ACCOUNT_EXIST='/opt/output/account_exist-'+datenow+'.csv'
ZM_SVR="10.58.122.209"
#-- DB Engine
engine = create_engine("mysql://root:paganini@localhost/homecredit")
#dataframe database_check_disable
query_disable = "select nik,d_name,upn,email,ad_feature,date_closed from tbl_users where status_employee = 1 and status_email = 1 and date_closed + NOW();"
source_db = pd.read_sql(query_disable, engine)
source_db.columns=['EmployeeNo','DisplayName','UPN','email','ad_feature','date_closed']
source_db['UserLogonName'] = source_db.UPN.str.split("@").str[0]
#Add date Created column
date_field = datenow
source_db['date_deleted'] = date_field
#Add new column for zimbra mandatory
source_db['zmprov']='zmprov'
source_db['ma']='ma'
source_db['zimbraAccountStatus']='zimbraAccountStatus'
source_db['closed']='closed'
# SPESIFY ACCOUNT BASED ON SYSTEM
AD = source_db.loc[(source_db.EmployeeNo.notnull()) & (source_db.ad_feature == "y")]
ZIMBRA = source_db.loc[(source_db.email.str.contains('ext.homecredit.co.id'))]
print (AD)
print (ZIMBRA)
# EXPORT to csv create zimbra
# Generate file for creating file zimbra
CONV_AD = AD.astype('str').replace('\.0', '', regex=True)
CONV_ZM = ZIMBRA.astype('str').replace('\.0', '', regex=True)
# FORMAT CREATE ZIMBRA
# zmprov ma user@domain.tld zimbraAccountStatus closed
zmfile = open(ZM_FILE,'w+')
CONV_ZM.to_csv(ZM_FILE,encoding='utf-8',sep=' ', index = None, header=None,mode = 'a', columns=['zmprov','ma','email','zimbraAccountStatus','closed'])
#Main Table AD Format
# Export to csv Untuk AD format dengan Exchange
tbl_adex=['EmployeeNo','DisplayName','UserLogonName']
CONV_AD.to_csv(ADEX_FILE, sep=',', encoding='utf-8', index = None, header=tbl_adex,columns=['EmployeeNo','DisplayName','UserLogonName'])
# ------------------------------------- SEND TO SSH and Email for result file
with open(ZM_FILE) as zimbra_file:
first = zimbra_file.read(1)
if not first:
print('\nZimbra Not Process:\nNot sending any Files, zimbra file is empty..\n')
else:
# send file zimbra to server zimbra - SSH
os.system("rsync -avh " +ZM_FILE+ " root@"+ZM_SVR+":/tmp/")
# archive file before remove
os.system("rsync -avh " +ZM_FILE+ " /opt/output/history/")
# remove zimbra file
os.system("rm -rf "+ZM_FILE+ ";echo 'file "+ZM_FILE+" success and file aready removed..!'")
print('\nZimbra Proceed :\nZimbra File already send to remote server\n')
#if not exchangefile.empty:
# print('\nAD and Exchange Process :\nExchange file process, Please check your Email.....\n')
# -- send mail
#os.system("echo 'Hi Team, \n\nWe send you file for creation AD account, please execute in poper systems. \n\nThanks\n\n IT Servers '| mailx -v -r 'amsnew@homecredit.co.id' -s 'AD Creation file "+datenow+"' -a "+ADEX_FILE+" -S smtp=smtp1-int.id.prod doni.hirmansyah01@homecredit.co.id firmandha.noerdiansya@homecredit.co.id")
#else:
# print ('\nAD and Exchange Process :\nExhcange file is empty, File Not Process....\n')