Script to get Disabled users in IICS
This script user Informatica Cloud APIs to get user details and pulls disabled and locked users even if SAML is integrated. You need to replace username, password, send email, receiver email and SMPT server so that it generated disabled users list for that org in the same path from where you are running the script.
import requests
import json
import sys
import datetime
import smtplib, ssl
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
filename="userslist.txt"
username = "username"
password = "Password"
current_timestamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
with open(filename, 'w') as f:
f.write(current_timestamp+'\n')
username = username
password = password
url = "https://dm-us.informaticacloud.com/saas/public/core/v3/login"
payload = json.dumps({
"username": username,
"password": password
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
login=json.loads(response.text)
for i in login:
if i=='userInfo':
#print(i, ":", login[i])
for a in login[i]:
if a=="sessionId":
sid=login[i][a]
import requests
url = "https://usw5.dm-us.informaticacloud.com/saas/public/core/v3/users?limit=200"
payload = {}
headers = {
'INFA-SESSION-ID': sid,
'Accept': 'application/json'
}
response = requests.request("GET", url, headers=headers, data=payload)
#print(response.text)
data=response.json()
for u in data:
if (u["state"]not in ["Enabled", "Provisioned"]):
user=u["userName"]
state=u["state"]
email=u["email"]
if u["authentication"]=="SAML":
print(user, state)
with open(filename, 'a') as f:
f.write(user+" "+ state+" "+ email+"\n")
url = "https://usw5.dm-us.informaticacloud.com/saas/public/core/v3/users?limit=200&skip=200"
response = requests.request("GET", url, headers=headers, data=payload)
#print(response.text)
data=response.json()
for u in data:
if (u["state"] not in ["Enabled", "Provisioned"]):
user=u["userName"]
state=u["state"]
email = u["email"]
if u["authentication"]=="SAML":
print(user, state)
with open(filename, 'a') as f:
f.writelines(user+" "+ state+" "+ email+"\n" )
url = "https://usw5.dm-us.informaticacloud.com/saas/public/core/v3/users?limit=200&skip=400"
response = requests.request("GET", url, headers=headers, data=payload)
#print(response.text)
data=response.json()
for u in data:
if (u["state"] not in ["Enabled", "Provisioned"]):
user=u["userName"]
state=u["state"]
email = u["email"]
if u["authentication"]=="SAML":
print(user, state)
with open(filename, 'a') as f:
f.writelines(user+" "+ state+" "+ email+"\n")
url = "https://usw5.dm-us.informaticacloud.com/saas/public/core/v3/users?limit=200&skip=600"
response = requests.request("GET", url, headers=headers, data=payload)
#print(response.text)
data=response.json()
for u in data:
if (u["state"] not in ["Enabled", "Provisioned"]):
user=u["userName"]
state=u["state"]
email = u["email"]
if u["authentication"]=="SAML":
print(user, state)
with open(filename, 'a') as f:
f.writelines(user+" "+ state+" "+ email+"\n" )
url = "https://usw5.dm-us.informaticacloud.com/saas/public/core/v3/users?limit=200&skip=800"
response = requests.request("GET", url, headers=headers, data=payload)
#print(response.text)
data=response.json()
for u in data:
if (u["state"] not in ["Enabled", "Provisioned"]):
user=u["userName"]
state=u["state"]
email = u["email"]
if u["authentication"]=="SAML":
print(user, state )
with open(filename, 'a') as f:
f.writelines(user+" "+ state+" "+ email+"\n")
url = "https://usw5.dm-us.informaticacloud.com/saas/public/core/v3/users?limit=200&skip=1000"
response = requests.request("GET", url, headers=headers, data=payload)
#print(response.text)
data=response.json()
for u in data:
if (u["state"] not in ["Enabled", "Provisioned"]):
user=u["userName"]
state=u["state"]
email = u["email"]
if u["authentication"]=="SAML":
print(user, state)
with open(filename, 'a') as f:
f.writelines(user+" "+ state+" "+ email+"\n")
url = "https://usw5.dm-us.informaticacloud.com/saas/public/core/v3/users?limit=200&skip=1200"
response = requests.request("GET", url, headers=headers, data=payload)
#print(response.text)
data=response.json()
for u in data:
if (u["state"] not in ["Enabled", "Provisioned"]):
user=u["userName"]
state=u["state"]
email = u["email"]
if u["authentication"]=="SAML":
print(user, state)
with open(filename, 'a') as f:
f.writelines(user+" "+ state+" "+ email+"\n")
with open(filename, 'r') as f:
file_content=f.read()
port = 25
smtp_server = "smtpserver.com"
sender_email = "senderemail"
receiver_email = "reciever email"
subject="locked users in Informatica"
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = subject
body=f"{file_content}"
message.attach(MIMEText(body, "plain"))
# context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.sendmail(sender_email, receiver_email, message.as_string())
Comments
Post a Comment