Slack integration with FileWave
Description
This macOS recipe uses a Fileset and a Slack incoming webhook to report low system-drive space. It demonstrates both warning and danger thresholds and spreads device checks across randomized weekdays and times.
Third-party integration. Slack configuration and webhook behavior are maintained by Slack. FileWave provides this recipe as an example rather than a supported Slack integration.
Requirements
- A Slack workspace, permission to create or install a Slack app, and an incoming webhook for the destination channel
- Provided Fileset - SlackDiskUsage.fileset.zip
The provided Fileset is for macOS, but similar could be applied to Windows.
Information
Current Slack incoming webhooks are created through Slack apps and are tied to a destination channel. The Fileset still contains legacy username, channel, and icon_emoji fields; Slack app webhooks ignore those legacy overrides.
\"username\": \"Helpdesk\",
\"channel\": \"#fw_messages\",
\"icon_emoji\": \":computer:\",
Configure the destination channel, app name, and icon in the Slack app settings.
Details on Legacy Webhooks:
https://api.slack.com/legacy/custom-integrations/incoming-webhooks
Directions
Slack Webhook
Create a Slack app, enable incoming webhooks, and add a webhook to the channel that should receive device alerts. Follow Slack's current guide:
Sending messages using incoming webhooks
Keep the webhook URL secret. Anyone with the URL can post to the configured channel, and Slack may revoke exposed webhook URLs.
Once generated, the Fileset may be configured to implement this Webhook.
Fileset Configuration
The Fileset has the following components:
- The script to report back to Slack
- A pre-install script that creates a plist containing the webhook and threshold configuration
- A LaunchDaemon to trigger the script
- An Activation and Pre-Uninstallation Script, to load/unload the daemon
Plist Configuration File
Once the Webhook has been generated, the Fileset should be edited to match the provided URL by replacing 'PLACE WEBHOOK HERE' with the created Webhook. This needs to be done by:
- Editing the Fileset
- Selecting 'slack_config_disk_usage.sh'
- Choose 'Get Info'
- Select 'Executable'
- Select 'Environment Variables' tab

Similarly, if using Legacy Webhooks, the slack_channel variable needs to be edited to match the name of the created channel; for App Webhooks it will be ignored. In the example, this channel is called 'fw_messages'
There are also two pairs of thresholds. One pair for percentage of disk used:
- space_danger
- space_warning
and a pair for the amount of disk space available (value in GB):
- space_danger_gb
- space_warning_gb
From the example Fileset, a warning message will be delivered if either:
- The percentage used exceeds 80%, the value for space_warning
- The amount of disk space is lower than 50GB, the value of space_warning_gb
However, a more stringent message will be delivered if either:
- The percentage used exceeds 90%, the value of space_danger
- The amount of free disk space is lower than 30 GB, the value of
space_danger_gb
These values should be edited to match desired requirement. Since the script is loaded as a launchd process, once loaded, changes to the script will only be adhered to if the launchd process is stopped and restarted. Providing an additional file, allows for values to be updated in the Fileset which the script will act upon when next triggered; without the need to restart the launchd process.
LaunchDaemon
The com.filewave.slack_drive_space.plist LaunchDaemon runs once per week on a randomized weekday between 09:00 and 18:00. The activation script selects the schedule for each device so the fleet does not post all checks at once. Fileset activation replaces the plist's default schedule values.
Details around the configuration of launchd may be seen at the following resource, should different timings be desired. Note that this would involve editing the Activation Script as well.
Example messages
Warning - Percentage drive space outside of threshold range and available disk space between Thresholds of 20GB and 40GB:

Danger - Percentage drive space outside of threshold range and available disk space lower than Thresholds of 30GB and 50GB:

For self designing messages, the above main scripts were based upon Slack's Secondary Attachments. Although Slack have only deprecated some items, indication is that all 'attachments' should not be relied upon and to consider their new Block feature.
https://api.slack.com/reference/messaging/attachments
Block Kit
Block Kit is really no different to 'attachments' and where some features are already incompatible with App Webhooks, others have been included through Block Kit. A similar look may be achieved:

For example,
- The deprecated attachment 'icon_emoji' may no longer be updated by a message and the icon is set through the settings for the App Webhooks. However, it is possible to add an image via a URL. Images may be added to the thread and then referenced by their URL; as the above example. Alternatively, numerous App Webhooks could be created with differing icons and the relevant Webhook could be referenced in each script.
- The attachment 'footer' can be replaced with an 'elements' block
- The 'mrkdwn' for Block Quotes does not allow for colouring the vertical line
- A 'divider' line may now be included to more clearly separate messages
Further details on designing text within Blocks:
https://api.slack.com/reference/surfaces/formatting
To reference images uploaded to Slack, they must be made publicly available. A public link should be of the format:
https://slack-files.com/{team_id}-{file_id}-{pub_secret}
The direct link to be referenced in a script has the format:
https://files.slack.com/files-pri/{team_id}-{file_id}/{filename}?pub_secret={pub_secret}
An example link may look like:
https://files.slack.com/files-pri/ABU1BH39Z-F0117AF5RRB/exclamation.jpg?pub_secret=5c56df27a5
Example json from the above. Variables have been replaced with values to allow for immediate testing:
json="{
\"blocks\": [
{
\"type\": \"section\",
\"text\": {
\"type\": \"mrkdwn\",
\"text\": \":red_circle:*1015VMDEP\tDisk Warning*\n*!!System Drive Space Low!!*\n>*Drive Space Used:* 32%\n>*Available:* 21GB\"
},
\"accessory\": {
\"type\": \"image\",
\"image_url\": \"https://api.slack.com/img/blocks/bkb_template_images/beagle.png\",
\"alt_text\": \"alt text for image\"
}
},
{
\"type\": \"context\",
\"elements\": [
{
\"type\": \"mrkdwn\",
\"text\": \"*model:* MacBook Pro (15-inch, 2019)\"
},
{
\"type\": \"mrkdwn\",
\"text\": \"*macOS*: 10.15.1\"
},
{
\"type\": \"mrkdwn\",
\"text\": \"*client:* 13.2.3\"
},
{
\"type\": \"mrkdwn\",
\"text\": \"*thresholds:* 90% 30GB\"
}
]
},
{
\"type\": \"divider\"
}
]
}"
Conclusion
Use a test Slack channel and pilot Macs to validate the webhook, thresholds, schedule, and message formatting before broad deployment. Adapt the same Fileset pattern for other device checks only after reviewing the script and the third-party API requirements.
No comments to display
No comments to display