Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
6a929d6a
Unverified
Commit
6a929d6a
authored
May 19, 2019
by
neil
Committed by
GitHub
May 19, 2019
Browse files
Merge pull request #2264 from honzahommer/notify-slack
Add slack notify
parents
ae380cb2
73bbe25d
Changes
1
Show whitespace changes
Inline
Side-by-side
notify/slack.sh
0 → 100644
View file @
6a929d6a
#!/usr/bin/env sh
#Support Slack webhooks
#SLACK_WEBHOOK_URL=""
#SLACK_CHANNEL=""
#SLACK_USERNAME=""
slack_send
()
{
_subject
=
"
$1
"
_content
=
"
$2
"
_statusCode
=
"
$3
"
#0: success, 1: error 2($RENEW_SKIP): skipped
_debug
"_statusCode"
"
$_statusCode
"
SLACK_WEBHOOK_URL
=
"
${
SLACK_WEBHOOK_URL
:-
$(
_readaccountconf_mutable SLACK_WEBHOOK_URL
)
}
"
if
[
-z
"
$SLACK_WEBHOOK_URL
"
]
;
then
SLACK_WEBHOOK_URL
=
""
_err
"You didn't specify a Slack webhook url SLACK_WEBHOOK_URL yet."
return
1
fi
_saveaccountconf_mutable SLACK_WEBHOOK_URL
"
$SLACK_WEBHOOK_URL
"
SLACK_CHANNEL
=
"
${
SLACK_CHANNEL
:-
$(
_readaccountconf_mutable SLACK_CHANNEL
)
}
"
if
[
-n
"
$SLACK_CHANNEL
"
]
;
then
_saveaccountconf_mutable SLACK_CHANNEL
"
$SLACK_CHANNEL
"
fi
SLACK_USERNAME
=
"
${
SLACK_USERNAME
:-
$(
_readaccountconf_mutable SLACK_USERNAME
)
}
"
if
[
-n
"
$SLACK_USERNAME
"
]
;
then
_saveaccountconf_mutable SLACK_USERNAME
"
$SLACK_USERNAME
"
fi
export
_H1
=
"Content-Type: application/json"
_content
=
"
$(
printf
"*%s*
\n
%s"
"
$_subject
"
"
$_content
"
| _json_encode
)
"
_data
=
"{
\"
text
\"
:
\"
$_content
\"
, "
if
[
-n
"
$SLACK_CHANNEL
"
]
;
then
_data
=
"
$_data
\"
channel
\"
:
\"
$SLACK_CHANNEL
\"
, "
fi
if
[
-n
"
$SLACK_USERNAME
"
]
;
then
_data
=
"
$_data
\"
username
\"
:
\"
$SLACK_USERNAME
\"
, "
fi
_data
=
"
$_data
\"
mrkdwn
\"
:
\"
true
\"
}"
if
_post
"
$_data
"
"
$SLACK_WEBHOOK_URL
"
;
then
# shellcheck disable=SC2154
if
[
"
$response
"
=
"ok"
]
;
then
_info
"slack send success."
return
0
fi
fi
_err
"slack send error."
_err
"
$response
"
return
1
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment