-
Notifications
You must be signed in to change notification settings - Fork 0
API Custom Scripts
- Methods
- Payload model
- List scripts
- Get a script
- Create a script
- Update a script
- Delete a script
- See also
The resource wraps the /api/v1/library/custom-scripts endpoint and exposes five methods:
| Method | Description | Returns |
|---|---|---|
list() |
All custom scripts | PayloadList[CustomScriptPayload] |
get(id) |
A single script by ID | CustomScriptPayload |
create(...) |
Create a script | CustomScriptPayload |
update(id, ...) |
Update an existing script | CustomScriptPayload |
delete(id) |
Delete a script | None |
Methods return a CustomScriptPayload with these key attributes:
| Attribute | Type | Description |
|---|---|---|
id |
str |
The library item ID (UUID) |
name |
str |
Display name |
active |
bool |
Whether the script is active |
execution_frequency |
str |
How often the script runs (see below) |
script |
str |
The script content |
remediation_script |
str |
The remediation script content (may be empty) |
restart |
bool |
Whether to restart after running |
show_in_self_service |
bool |
Whether the script appears in Self Service |
self_service_category_id |
str | None |
Self Service category ID, when shown |
execution_frequency accepts the ExecutionFrequency enum:
ExecutionFrequency.ONCE # "once"
ExecutionFrequency.EVERY_15_MIN # "every_15_min"
ExecutionFrequency.EVERY_DAY # "every_day"
ExecutionFrequency.NO_ENFORCEMENT # "no_enforcement"Listed scripts are returned in a PayloadList with count and results properties.
with CustomScriptsResource(config) as scripts:
for script in scripts.list().results:
print(f"{script.id} {script.name} ({script.execution_frequency})")# Gets a single script and prints the audit script content
with CustomScriptsResource(config) as scripts:
script = scripts.get("ae492437-c35f-46a3-bd0b-21188a69dfb1")
print(script.script)At minimum, provide a name and the script content. Add a remediation_script to pair an
audit script with its fix, and set execution_frequency to control how often it runs.
The create method returns the created script, including the id.
audit = """\
#!/bin/sh
[ -f /Library/Example/flag ] || exit 1
"""
remediation = """\
#!/bin/sh
touch /Library/Example/flag
"""
with CustomScriptsResource(config) as scripts:
created = scripts.create(
name="Ensure example flag",
script=audit,
remediation_script=remediation,
active=True,
execution_frequency=ExecutionFrequency.EVERY_DAY,
)
print(f"Created {created.name} ({created.id})")To surface a script in Self Service, set show_in_self_service=True and supply a
self_service_category_id. Look up category IDs with
Self Service Categories.
with CustomScriptsResource(config) as scripts:
scripts.create(
name="Reset printers",
script="#!/bin/sh\n/usr/bin/lpadmin -x ...\n",
execution_frequency=ExecutionFrequency.NO_ENFORCEMENT,
show_in_self_service=True,
self_service_category_id="ae492437-c35f-46a3-bd0b-21188a69dfb1",
self_service_recommended=True,
)Important
create() and update() raise ValueError if:
-
execution_frequencyisNO_ENFORCEMENTbutshow_in_self_serviceis not set -
show_in_self_serviceisTruebut noself_service_category_idis provided
Pass only the id and the fields you want to change. update returns the full updated
script object.
with CustomScriptsResource(config) as scripts:
updated = scripts.update(
"ae492437-c35f-46a3-bd0b-21188a69dfb1",
active=False,
)
print(f"Updated {updated.name} ({updated.id})")
print(f"active={updated.active}")Deleting a script only requires the id and does not return anything.
with CustomScriptsResource(config) as scripts:
scripts.delete("ae492437-c35f-46a3-bd0b-21188a69dfb1")- Custom Scripts — the on-disk repository format for scripts.
- Self Service Categories — find category IDs.
Getting Started
Working with Resources
- Populating Your Local Repository
- Editing Resources
- Self Service
- Pushing and Syncing
- Listing and Showing Resources
- Deleting Resources
- Blueprint Assignment
Reference
Python API Client