Problem retrieving the values of conditional items

26 views
Skip to first unread message

Marcus Siöström

unread,
Aug 15, 2016, 9:08:48 AM8/15/16
to sal-discuss
Hi,

I'm quite new to Sal and Python and have ran into a slight snag.

I'm trying to create a list plugin in Sal where I'd like to use the string that is being set in Munki's Conditional Items, however, I'm having some trouble retrieving the data. 

I've based my plugin on the standard MunkiVersion plugin and I'm trying to use the .values() method to retrieve the data that was set by Munki but for some reason, nothing gets returned.

I've verified that the data is present in Sal under "MSC Conditions" for the specific machine and I can use the .filter() method to get boolean data:
machines.filter(conditions__condition_name='flash_version', conditions__condition_data='22.0.0.209')


When I try to get the value by using something like this, nothing gets returned:
machines.values(conditions__condition_name='flash_version')


While troubleshooting, I ran machines.values() and noticed that not all data is formated the same. It looks like some data uses JSON format wile other uses plist format:
 'munki_version': u'2.8.0.2810',
<key>flash_version</key>\n\t\t<string>22.0.0.209</string>\n\t\t


After some trial and error, I found that the .values() method is only possible to use on data that's formated in JSON.


Am I missing something or is Sal simply not designed to be able to do this?



Thanks!


Graham Gilbert

unread,
Aug 15, 2016, 11:08:33 AM8/15/16
to sal-d...@googlegroups.com
It looks like your script isn't saving it's data as you would expect. I would start looking there - hard to say more without actual code to look at.

--
You received this message because you are subscribed to the Google Groups "sal-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sal-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Siöström

unread,
Aug 16, 2016, 3:12:10 AM8/16/16
to sal-discuss
Do you mean the conditions script that's running on the client?

Here's the client code:

$ cat /usr/local/munki/conditions/flash_version
#!/bin/bash

DEFAULTS=/usr/bin/defaults
MUNKI_DIR=$($DEFAULTS read /Library/Preferences/ManagedInstalls ManagedInstallDir)
COND_DOMAIN="$MUNKI_DIR/ConditionalItems"
FLASH_VERS=$($DEFAULTS read /Library/Internet\ Plug-Ins/Flash\ Player.plugin/Contents/version.plist CFBundleVersion 2>/dev/null)
if [ -z $FLASH_VERS ]; then FLASH_VERS="None"; fi
$DEFAULTS write "$COND_DOMAIN" flash_version "$FLASH_VERS"


Attaching a screenshot from Sal showing the data
To unsubscribe from this group and stop receiving emails from it, send an email to sal-discuss...@googlegroups.com.
Screen Shot 2016-08-16 at 09.09.45.png

Graham Gilbert

unread,
Aug 17, 2016, 11:36:00 AM8/17/16
to sal-d...@googlegroups.com
Sorry, I didn't read closely enough.

machines.values(conditions__condition_name='flash_version') isn't valid in Django. What are you trying to do exactly? What data do you need to retrieve / display? Basically you will need to:

machines.filter(conditions__condition_name='flash_version')

and then do something with that. You might want to get all the values of flash you have and then annotate the queryset with the count of each one perhaps? I'd just be guessing though.

To unsubscribe from this group and stop receiving emails from it, send an email to sal-discuss+unsubscribe@googlegroups.com.

Marcus Siöström

unread,
Aug 18, 2016, 7:47:37 AM8/18/16
to sal-discuss
I finally figured this out and thought that I'd share my solution.

I found that if I add a script to /usr/local/munki/conditions, It will show up in Sal in plist format. This was the root of my issues as I could not use attributes like .values() to get the data that the script was providing. Perhaps it is possible to do this somehow but as my Django knowledge is close to zero, I couldn't figure it out.

My solution where to add my script as a factor script (/usr/local/sal/facter) which would format the data in json which allowed me to use the .values() attribute. This was needed as my goal was to create a pie chart (like the Munki Version plugin) that displayed the data:

As for the plugin, I simply copied the Munki Version plugin and changed the data source to the following:
Fact.objects.filter(fact_name='custom_flash_version').values('fact_data').annotate(count=Count('fact_data')).order_by('fact_data')
Reply all
Reply to author
Forward
0 new messages