GithubHelp home page GithubHelp logo

staticgroupfromsearch's Introduction

Static Group from Search

Description


This Python script performs a search on a JSS using the '/match' API endpoint for Computers or Mobile Devices and creates a Static Group of the results.

The script takes arguments and contains built-in help text.

Usage


A single phrase can be passed as the search criteria or a list provided in CSV format. Any searchable criteria for an inventory record can be used along with wild card values (*).

CSV lists can contain a mix of values such as usernames, email addresses, serial numbers, MAC addresses, etc. Your CSV file should be formatted as a single column without a header:

value1
value2
value3

Passing an asterisk (*) as the criteria will return all device records.

Help Text


Script help text show here:

usage: StaticGroupFromSearch [-h] (-c | -m) (-f FILE | -s SEARCH)
                             [-u USERNAME] [-p PASSWORD]
                             jssurl groupname

Use the '/match' endpoint for Computers and Mobile devices to generate Static Groups.

positional arguments:
  jssurl                JSS URL
  groupname             new static group name

optional arguments:
  -h, --help            show this help message and exit
  -c, --computers       search computers
  -m, --mobiledevices   search mobile devices
  -f FILE, --csv-file FILE
                        read search values from csv file
  -s SEARCH, --search SEARCH
                        search for a value
  -u USERNAME, --username USERNAME
                        API username
  -p PASSWORD, --password PASSWORD
                        API user password

Example usage:
$ ./StaticGroupFromSearch.py https://jss.myorg.com "Contains 'iPhone'" -u 'user' -p 'pass' --mobiledevices -s '*iPhone*'
$ ./StaticGroupFromSearch.py https://jss.myorg.com "Starts with 'admin'" --computers --search 'admin*'
$ ./StaticGroupFromSearch.py https://jss.myorg.com "Devices from list" --mobiledevices --csv-file /path/to/list.csv.csv

staticgroupfromsearch's People

Contributors

brysontyrrell avatar cybertunnel avatar homebysix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

staticgroupfromsearch's Issues

No longer working in 9.96

Thank you very much for this script.
I had to add after line 126 to get it working in the latest version of Casper suite.
request.add_header('Accept', 'application/xml')

Issue with parsing XML

Any command I do results with the following error:

python StaticGroupFromSearch.py url "test" -u 'test' -p 'test' --computers --csv-file Workbook2.csv
performing search on the JSS at: ../JSSResource/computers/match/lshanny2-mac
Traceback (most recent call last):
File "StaticGroupFromSearch.py", line 206, in
main()
File "StaticGroupFromSearch.py", line 185, in main
results = jss.get_match(value)
File "StaticGroupFromSearch.py", line 116, in get_match
return etree.fromstring(self.request(request))
File "", line 124, in XML
cElementTree.ParseError: not well-formed (invalid token): line 1, column 0

JSS version: 10.1.1-t1513360285
Python: 2.7.14

Tried different ways to save the CSV file, different args, including the examples provided, and a different API account. All give me the same issue.

Possibly search based on computer ID?

I initially tried this to replicate a script that JAMF prof services gave me when we were trouble shooting an issue - "Create-Static-Computer-Group.py". Based on using that, I was trying to create a list using the computer numbers as a search criteria. Once I fixed that mistake and used a different criteria, it worked, but doing it by computer ID might be useful in cases where computers names changed but the ID didn't (because of a migration, etc).

Thanks!

Problem with TLSv1

self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1)

I was getting the following error:

an error occurred during the search: URLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:590)
check the server URL used and try again

Which I believe is because of new TLS requirements in Jamf Pro. Removing "ssl_version=ssl.PROTOCOL_TLSv1" allowed it to work. Are there any implications with removing this? If not, I'd be happy to submit a PR.

Stopped Working

Traceback (most recent call last):
File "/Users/*_/Desktop/StaticGroupFromSearch-master/StaticGroupFromSearch.py", line 136, in
results = jss.get_match(i)
File "/Users/_
/Desktop/StaticGroupFromSearch-master/StaticGroupFromSearch.py", line 78, in get_match
print("an error occurred during the GET: {0}".format(e.code))
AttributeError: 'URLError' object has no attribute 'code'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.