I was working on a script to automate the license count for JIRA Software (Server), also send an email everyday about the count of licenses.
Hope this script helps someone looking for a solution to count jira licenses
I have used basic Python requests module for this. Tweak the code for your own use.
#Package for REST API CALL and json formattingimport requestsimport json#Packages for Emailimport smtplibfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextfrom email.mime.base import MIMEBasefrom email import encodersheaders = { 'Accept': '*/*',}url= 'https://jira.example.com/rest/plugins/applications/1.0/installed/jira-software'r=requests.get(url=url,headers=headers,auth=("username","password"),verify=False)print(r.status_code)data=json.loads(r.text)activeUsers = data['accessDetails']['activeUserCount']#print("There are currently %d counted towards JIRA Software License" % (activeUsers))licensedUsers = data['accessDetails']['licensedUserCount']remainingLicenses= licensedUsers - activeUsers#print("There are %d licenses left" % (remainingLicenses))#Send Emailrecepients=['user1@example.com']fromaddr="user2@example.com"msg=MIMEMultipart()msg['From']=fromaddrmsg['To']=", ".join(recepients)msg['Subject']="JIRA License Information" body="There are currently" + " " +str(activeUsers)+ " "+ "accounts counted towards JIRA Software License [2000 User License]"msg.attach(MIMEText(body,'plain'))server=smtplib.SMTP('smtp.example.com',25)text=msg.as_string()server.sendmail(fromaddr,recepients,text)server.quit()
Ref: https://stackoverflow.com/questions/24077314/how-to-send-an-email-with-style-in-python3
Email Screenshot
Hope this helps getting started.
Thank You
Chander Inguva
Does this work for jira cloud ?
Hey Krishna,
Please try setting the URL to Jira Cloud, unfortunately i do not have a cloud instance to check it.
I believe it should work.
Hello Chander,
I haven't tried this script yet but I'm whiling to do it right now and would like to thank you even before actually trying it out.
Thank's for sharing this!
This doesn't seem to work anymore. The url is no longer valid. Anyone found a different approach?
This api doesn't work now.
Any other solution.?
Thanks,
Irfan Ansari
It looks like you're new here. Sign in or register to get started.