Comment or Note field (not through EA or SQL Command)

glpi-ios
Contributor III

Hello everybody,

Please, can you tell me if it is possible, and if not, if there is a trick to add a custom comment or custom note for each computer on the JSS Web without having to go through Attribute Extensions ?
Because if we use the Attribute Extension, the computer must be turned on to execute an inventory ...

For example, some computers are in the Jamf inventory but have not been turned on for some time. We would like to add a comment in the JSS database without having to go through SQL commands.

Thank you, and have a good day

1 ACCEPTED SOLUTION

ryan_ball
Valued Contributor

@glpi-ios You are probably looking at an Extension Attribute with "Input Type" set as "Text Field". This would allow you to actually edit the field from the GUI or populate the field VIA API using a script similar to below:

#!/bin/bash

# https://www.jamf.com/jamf-nation/discussions/30775/comment-or-note-field-not-through-ea-or-sql-command

xmlPath='/tmp/tmp.xml'  # Create our XML file for API PUT
eaName="This is the name of my EA"   # Extension Attribute name
eaValue="Some Text Here"
serial=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}')
jssUser=""
jssPass=''
jssURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed s'/.$//')

function api_post () {
    cat <<EndXML > "$xmlPath"
<?xml version="1.0" encoding="UTF-8"?>
<computer>
    <extension_attributes>
        <extension_attribute>
            <name>$eaName</name>
            <type>String</type>
            <value>$eaValue</value>
        </extension_attribute>
    </extension_attributes>
</computer>
EndXML

    # Attempt to put the XML to the Jamf Pro Server
    result=$(curl -sk -u "$jssUser:$jssPass" -H 'Content-type: text/xml' "$jssURL/JSSResource/computers/serialnumber/${serial}/subset/extension_attributes" -T "$xmlPath" -X PUT)

    # Check for errors in the PUT result
    if [[ $result =~ "Error" ]] || [[ $result =~ "Conflict" ]] || [[ $result =~ "Unauthorized" ]]; then
        echo "There was an error PUTing the XML file to the Jamf Pro Server."
        exit 1
    else
        echo "Successfully updated the $eaName field in the Jamf Pro Server."
    fi
}

api_post

exit 0

However, these devices would also not have checked in to the Jamf Pro Server in a certain amount of days as well because they would have been off. In that case you could also use an Advanced Search or Smart Group to see devices where "Last Check-in" is more than X days. This would require no EA or scripting.

View solution in original post

5 REPLIES 5

mm2270
Legendary Contributor III

Well, you could always look at using actual attachments and an API script to upload those attachments to the computer record. That is, unless you wanted to somehow be able to search for systems based on what's in the note. If that is the case, then an EA would be the only real option as far as I know. Attachments to my knowledge, cannot be searched on in the UI. You have to actually download the attachment from the record to view it again.

ryan_ball
Valued Contributor

@glpi-ios Just to confirm, you want to add some sort of a comment to the device record of a Mac that has not been turned on in X amount of time?

glpi-ios
Contributor III

@mm2270 Thanks for your answer.

@ryan.ball This is one of many examples.
I would like to put a comment on the JSS Web on some computers without them being turned on to make an inventory and inform an EA.
For example, a custom field that would be editable directly on the JSS Web.

Maybe I could use Asset Tag, right?
I can edit directly in JSS Web and can use it as search criteria.

Do you believe it is possible?
Is there a character limit for this field ?

At worst, I imagine I can create an EA and feed it by API?

ryan_ball
Valued Contributor

@glpi-ios You are probably looking at an Extension Attribute with "Input Type" set as "Text Field". This would allow you to actually edit the field from the GUI or populate the field VIA API using a script similar to below:

#!/bin/bash

# https://www.jamf.com/jamf-nation/discussions/30775/comment-or-note-field-not-through-ea-or-sql-command

xmlPath='/tmp/tmp.xml'  # Create our XML file for API PUT
eaName="This is the name of my EA"   # Extension Attribute name
eaValue="Some Text Here"
serial=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F" '/IOPlatformSerialNumber/{print $(NF-1)}')
jssUser=""
jssPass=''
jssURL=$(defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url | sed s'/.$//')

function api_post () {
    cat <<EndXML > "$xmlPath"
<?xml version="1.0" encoding="UTF-8"?>
<computer>
    <extension_attributes>
        <extension_attribute>
            <name>$eaName</name>
            <type>String</type>
            <value>$eaValue</value>
        </extension_attribute>
    </extension_attributes>
</computer>
EndXML

    # Attempt to put the XML to the Jamf Pro Server
    result=$(curl -sk -u "$jssUser:$jssPass" -H 'Content-type: text/xml' "$jssURL/JSSResource/computers/serialnumber/${serial}/subset/extension_attributes" -T "$xmlPath" -X PUT)

    # Check for errors in the PUT result
    if [[ $result =~ "Error" ]] || [[ $result =~ "Conflict" ]] || [[ $result =~ "Unauthorized" ]]; then
        echo "There was an error PUTing the XML file to the Jamf Pro Server."
        exit 1
    else
        echo "Successfully updated the $eaName field in the Jamf Pro Server."
    fi
}

api_post

exit 0

However, these devices would also not have checked in to the Jamf Pro Server in a certain amount of days as well because they would have been off. In that case you could also use an Advanced Search or Smart Group to see devices where "Last Check-in" is more than X days. This would require no EA or scripting.

glpi-ios
Contributor III

@ryan.ball Thank you very much, it helps me a lot.

Regarding computers that do not respond, I already created an Advanced Search but we wanted to add comments such as 'on extended leave', 'On sick leave for 10 months, 'sent for repairs', ...

But "Text Field" in EA is perfect and your script will help me too.

I am so ashamed because it was so simple. However I use EA a lot :-(

Thank you all for your help...