Skip to content

Instantly share code, notes, and snippets.

@ryanrhanson
Last active December 29, 2015 17:49
Show Gist options
  • Save ryanrhanson/7707224 to your computer and use it in GitHub Desktop.
Save ryanrhanson/7707224 to your computer and use it in GitHub Desktop.
Due to an Internal Server Error with http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer/getLoginAttempts and http://sldn.softlayer.com/reference/services/SoftLayer_Account/getUsers, this is a temporary workaround to grab the last 5 login attempts for each portal user.
#Last 5 login attempts for User1
#- Successful login from 123.45.67.89 at 2013-11-28T15:29:32-06:00
#- Failed login from 123.45.67.89 at 2013-11-28T15:29:23-06:00
#- Failed login from 123.45.67.89 at 2013-11-28T15:29:22-06:00
#- Successful login from 123.45.67.89 at 2013-11-27T15:13:49-06:00
#- Successful login from 123.45.67.89 at 2013-11-26T08:35:12-06:00
#
#Last 5 login attempts for User2
#- Successful login from 123.45.67.89 at 2013-11-16T04:51:42-06:00
#- Successful login from 123.45.67.89 at 2013-11-16T04:50:29-06:00
#- Successful login from 123.45.67.89 at 2013-11-11T03:45:22-06:00
#- Failed login from 123.45.67.89 at 2013-11-11T03:45:17-06:00
#
#Last 5 login attempts for User3
#- Successful login from 123.45.67.89 at 2013-11-06T08:57:15-06:00
import SoftLayer
#apiconfig is a file containing my apiUser and apiKey
from apiconfig import *
client=SoftLayer.Client(username=apiUser,api_key=apiKey)
#Set up our users list. We need an object mask to grab the 'users' from the SoftLayer Account object, and the loginAttempts from within the user list.
users_list = client['Account'].getObject(mask="mask[users[loginAttempts]]")
for user in users_list['users']:
if user['loginAttempts']:
print "\nLast 5 login attempts for %s" % (user['username'])
for login in user['loginAttempts'][:5]:
print "- %s login from %s at %s" % ('Successful' if login['successFlag'] else 'Failed', login['ipAddress'],login['createDate'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment