You can easily grab files from your devices and post them to Slack using a Slack Apps bot or user API's and a simple curl command.
Uploading files to Slack
The below link advises on this Slack process:
https://api.slack.com/messaging/files/uploading
Take some time to read the safety considerations for your Slack workspace. Use tokens carefully.
Uploading Files
Now that you have your token, here's the simplest method for uploading files from Addigy. These commands can easily be run right on the Devices page. Simply replace the text after file=, initial_comment=, channels=, and Authorization: Bearer with your desired file on the target device, desired slack message, the channel it should be sent to, and your Slack App Bot/User API token.
curl -F file=@/full/path/to/cycling.jpeg -F "initial_comment=Hello, Leadville" -F channels=C0R7MFNJD -H "Authorization: Bearer xoxp-123456789" https://slack.com/api/files.upload
Here's what successfully running the above command within Addigy on the Devices page should look like:
And this is what the upload will look like in Slack.
Get Creative
This simple integration can do a lot if you or your customers use Slack. Here in the Addigy Support team, we commonly use Slack as a simple method for collecting and uploading device logs.
This script is a sample of how you could quickly pull logs from your device into your Slack workspace.
#!/bin/bash
# https://api.slack.com/authentication/basics
# Based on this article: https://support.addigy.com/hc/en-us/articles/4403542603795-Uploading-Files-from-a-Device-to-Slack
device=$(hostname | cut -d. -f1)
serial=$(ioreg -c IOPlatformExpertDevice -d 2 | awk -F\" '/IOPlatformSerialNumber/{print $(NF-1)}')
org_id=$(/Library/Addigy/go-agent agent orgid)
current_date_time=$(date)
file_name="${device} | Log Upload | ${current_date_time}.tar.gz"
file_dir="${device} | ${org_id} | ${serial} | ${current_date_time}"
slack_token='SLACK TOKEN'
slack_message="Addigy Logs:
Device Name: ${device}
Serial Number: ${serial}
OrgID: ${org_id}
Date: ${current_date_time}"
slack_channel="SLACK CHANNEL"
# Create a Temp Directory
mkdir "${file_dir}"
# Create a system report.
system_profiler -xml > "${file_dir}"/system_information.spx
# Get Running Processes
ps aux > "${file_dir}"/processes.txt
# Get install log
cp /var/log/install.log "${file_dir}"/apple-install.log
# Copy over Addigy logs
cp /Library/Addigy/logs/* "${file_dir}"
# Display the contents of the directory
echo "DIRECTORY FILES:"
ls -l "${file_dir}"
# Archive logs
tar -czvf "${file_name}" "${file_dir}"
# Upload file to Slack using curl
response=$(curl -F file=@"${file_name}" -F initial_comment="${slack_message}" -F channels="${slack_channel}" -H "Authorization: Bearer ${slack_token}" https://slack.com/api/files.upload)
echo "Response: $response"
if [[ $response == *"ok\":true"* ]]; then
echo "File uploaded successfully!"
else
echo "File upload failed."
exit 1
fi
# Clean up
rm -rf "${file_dir}" # Use the correct path for removal
rm "${file_name}" # Remove the archive file after upload
Scripts like this can easily be run from the Run Commands section on the Devices page or the Scripts tab in GoLive. For more insight on running scripts on devices, check out our article, Creating and Running Scripts on Your Devices.
And this is what the upload will look like in Slack for the Addigy Logs.