Automate Users removal from Casper via REST API

One thing I wished Casper could do is remove users from the Users section after an asset is deleted from Casper.
Granted this may not be a situation for everyone but for me, I end up with lots of disabled users still showing up in my Users section.
While I can manually remove them, doing it every time, a hundred times is not ideal.

Thankfully, Casper has a REST API which let’s you interact with the JSS and get it done.
Shea Craig wrote a python-jss module which makes interacting with the JSS very simple.
Create a service account in your JSS (for my needs, I needed READ ONLY for Computers, Mobile Devices and READ and DELETE for Users), that account is what will be used in the script to access the JSS and do what needs to be done, uncheck everything else.
I have put together a setup script that installs the python-jss and the Slack API module so you can send result to a slack channel. Once all dependencies are installed (setup.py needs git and we assume you have that covered) the script which goes through the JSS, looks at all the users and identify the users who do not have a computer assigned to them.
Once those users have been identified, they get deleted from the JSS and then an email with the name of those users is sent to the address of my choice.

Screen Shot 2015-05-09 at 7.09.35 PM

Tied to a once a week cron job, I can ensure everything is running smoothly.
Both scripts (setup and user_cleanup) are available on my github.
As always feedbacks are welcome; I hope someone also finds it useful.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s