Skip to content

Instantly share code, notes, and snippets.

@sheagcraig
Last active August 29, 2015 14:25
Show Gist options
  • Save sheagcraig/5db35185fa9e4858c483 to your computer and use it in GitHub Desktop.
Save sheagcraig/5db35185fa9e4858c483 to your computer and use it in GitHub Desktop.
UpdateWarrantyExpiresGroup.py
#!/usr/bin/python
# 2015 Shea G. Craig
# ____ ______ __
# / ___/ ___\ \/ /
# | | _\___ \\ /
# | |_| |___) / \
# \____|____/_/\_\
# NO WARRANTY FOR YOU!
from xml.etree import ElementTree
import jss
# You'll need to have your com.github.sheagcraig.python-jss preferences
# configured prior to running for the first time!
jss_prefs = jss.JSSPrefs()
j = jss.JSS(jss_prefs)
GROUP_NAME = "Computers with blank warranty_expires value"
try:
no_warranty_expires_group = j.ComputerGroup(GROUP_NAME)
except jss.exceptions.JSSGetError:
# Group doesn't exist, so create it.
no_warranty_expires_group = jss.ComputerGroup(j, GROUP_NAME)
# Clear the group.
# Just in case we are using an older python-jss, and the group didn't
# exist already, let's ensure there's a "computers" list...
if no_warranty_expires_group.find("computers") is None:
computers_element = ElementTree.SubElement(no_warranty_expires_group,
"computers")
else:
no_warranty_expires_group.clear_list("computers")
# Build a list of all computers with a blank "warranty_expires" value.
blank_warranty_expires = [computer for computer in j.Computer().retrieve_all()
if computer.findtext("purchasing/warranty_expires")
== ""]
# Add in the results from list comp.
for computer in blank_warranty_expires:
no_warranty_expires_group.add_computer(computer)
# And save our work!
no_warranty_expires_group.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment