Skip to content

Instantly share code, notes, and snippets.

@fogonthedowns
Last active August 19, 2017 20:38
Show Gist options
  • Save fogonthedowns/7a6cb46bd7080630c49ee61811530bee to your computer and use it in GitHub Desktop.
Save fogonthedowns/7a6cb46bd7080630c49ee61811530bee to your computer and use it in GitHub Desktop.
Go Slack Webhook
// webhookUrl "https://hooks.slack.com/services/somehash/somehash/somehash"
package main
import (
"fmt"
"log"
"os"
"os/exec"
"github.com/ashwanthkumar/slack-go-webhook"
)
func main() {
webhookUrl := os.Args[1]
out, err := exec.Command("nvidia-smi").Output()
if err != nil {
log.Fatal(err)
}
fmt.Printf("The date is %s\n", out)
s := fmt.Sprintf("nvidia-smi: ``` %s ```", out)
payload := slack.Payload {
Text: s,
Username: "ETH Miner",
Channel: "#ocarina",
IconEmoji: ":monkey_face:",
}
errors := slack.Send(webhookUrl, "", payload)
if len(errors) > 0 {
fmt.Printf("error: %s\n", errors)
}
}
@fogonthedowns
Copy link
Author

go get github.com/ashwanthkumar/slack-go-webhook
go build slack-webhook.go

then add to crontab:

crontab -e
*/10 * * * * cd /path/to/command; ./slack-webhook https://hooks.slack.com/services/somehash/somehash/somehash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment