Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
joohanhong
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JooHan Hong
joohanhong
Commits
eef811f1
Commit
eef811f1
authored
Mar 11, 2021
by
JooHan Hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zabbix, update
parent
0620a731
Pipeline
#5171
passed with stages
in 46 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
51 deletions
+74
-51
Dockerfile
DOCKER/ZABBIX/Dockerfile
+4
-1
README.md
DOCKER/ZABBIX/README.md
+70
-50
zabbix_mattermost.png
DOCKER/ZABBIX/images/zabbix_mattermost.png
+0
-0
No files found.
DOCKER/ZABBIX/Dockerfile
View file @
eef811f1
...
...
@@ -18,7 +18,7 @@ RUN yum -y install epel-release
RUN
yum
-y
install
glibc glibc-common openssl-devel net-tools vi vim iproute wget postfix cronie crontabs supervisor
RUN
rpm
-ivh
https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
#RUN rpm -ivh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
RUN
yum
-y
install
zabbix-server-mysql zabbix-web-mysql zabbix-agent mysql httpd mod_ssl
RUN
yum
-y
install
zabbix-server-mysql zabbix-web-mysql zabbix-agent mysql httpd mod_ssl
python-pip
#RUN yum -y remove php-common-5.4.16-48.el7.x86_64 php-ldap-5.4.16-48.el7.x86_64 php-pdo-5.4.16-48.el7.x86_64 php-bcmath-5.4.16-48.el7.x86_64 php-xml-5.4.16-48.el7.x86_64 php-mbstring-5.4.16-48.el7.x86_64 php-cli-5.4.16-48.el7.x86_64 php-mysql-5.4.16-48.el7.x86_64 php-gd-5.4.16-48.el7.x86_64 php-5.4.16-48.el7.x86_64
#RUN yum -y install php70 php70-php-bcmath php70-php-dba php70-php-enchant php70-php-gd php70-php-gmp php70-php-imap php70-php-interbase php70-php-intl php70-php-ldap php70-php-mbstring php70-php-mcrypt php70-php-mysql php70-php-odbc php70-php-opcache php70-php-pgsql php70-php-dbg php70-php-pspell php70-php-recode php70-php-snmp php70-php-soap php70-php-tidy php70-php-xml php70-php-xmlrpc php70-php-zip php70-php-pear
...
...
@@ -26,9 +26,12 @@ COPY config/zabbix_server.conf /etc/zabbix/zabbix_server.conf
COPY
config/supervisord.conf /etc/supervisor/supervisord.conf
COPY
config/zabbix.conf /etc/supervisor/conf.d/zabbix.conf
COPY
config/php.ini /etc/php.ini
RUN
pip
install
requests
RUN
chown
-R
apache.apache /etc/zabbix/web
RUN
rm
-rf
/etc/alternatives/zabbix-web-font
RUN
mv
/usr/share/fonts/dejavu/DejaVuSans.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf_bak
COPY
config/fonts/NanumFont/NanumGothic.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf
COPY
config/bashrc /root/.bashrc
...
...
DOCKER/ZABBIX/README.md
View file @
eef811f1
...
...
@@ -32,16 +32,19 @@ ENV LC_ALL en_US.UTF-8
RUN yum
-y
install
epel-release
RUN yum
-y
install
glibc glibc-common openssl-devel net-tools vi vim iproute wget postfix cronie crontabs supervisor
RUN yum
-y
install
glibc glibc-common openssl-devel net-tools vi vim iproute wget postfix cronie crontabs supervisor
python-pip
RUN rpm
-ivh
https://repo.zabbix.com/zabbix/4.4/rhel/7/x86_64/zabbix-release-4.4-1.el7.noarch.rpm
COPY config/zabbix_server.conf /etc/zabbix/zabbix_server.conf
COPY config/supervisord.conf /etc/supervisor/supervisord.conf
COPY config/zabbix.conf /etc/supervisor/conf.d/zabbix.conf
COPY config/php.ini /etc/php.ini
RUN pip
install
requests
RUN
chown
-R
apache.apache /etc/zabbix/web
RUN
rm
-rf
/etc/alternatives/zabbix-web-font
RUN
mv
/usr/share/fonts/dejavu/DejaVuSans.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf_bak
COPY config/fonts/NanumFont/NanumGothic.ttf /usr/share/fonts/dejavu/DejaVuSans.ttf
COPY config/bashrc /root/.bashrc
...
...
@@ -53,61 +56,78 @@ CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
```
> `!중요` : Mattermost의 Push Alert을 위해서는 python pip 패키지설치 및 request 모듈의 설치가 필요하다.
## Mattermost Push Alert Script
## Mattermost Push Alert Script
```
bash
# cat mattermost.sh
#!/bin/bash
url
=
'https://chat.hongsnet.net/hooks/XXXXXXXXXXX'
username
=
'zabbix'
# Get the user/channel ($1), subject ($2), and message ($3)
to
=
"
$1
"
subject
=
"
$2
"
message
=
"
$3
"
recoversub
=
'^RECOVER(Y|ED)?$|^OK$|^Resolved.*'
problemsub
=
'^PROBLEM.*|^Problem.*'
if
[[
"
$subject
"
=
~
$recoversub
]]
;
then
emoji
=
':smile:'
color
=
'#0C7BDC'
elif
[[
"
$subject
"
=
~
$problemsub
]]
;
then
emoji
=
':frowning:'
color
=
'#FFC20A'
else
emoji
=
':question:'
color
=
'#CCCCCC'
fi
# Replace the above hard-coded Slack.com web-hook URL entirely, if one was passed via the optional 4th parameter
url
=
${
4
-
$url
}
# Use optional 5th parameter as proxy server for curl
proxy
=
${
5
-
""
}
if
[[
"
$proxy
"
!=
''
]]
;
then
proxy
=
"-x
$proxy
"
fi
# Build JSON payload which will be HTTP POST'ed to the Slack.com web-hook URL
payload
=
"payload={
\"
channel
\"
:
\"
${
to
//\
"/
\\\"
}
\"
,
\
\"
username
\"
:
\"
${
username
//\
"/
\\\"
}
\"
,
\
\"
attachments
\"
: [{
\"
fallback
\"
:
\"
${
subject
//\
"/
\\\"
}
\"
,
\"
title
\"
:
\"
${
subject
//\
"/
\\\"
}
\"
,
\"
text
\"
:
\"
${
message
//\
"/
\\\"
}
\"
,
\"
color
\"
:
\"
${
color
}
\"
}],
\
\"
icon_emoji
\"
:
\"
${
emoji
}
\"
}"
# Execute the HTTP POST request of the payload to Slack via curl, storing stdout (the response body)
return=
$(
curl
$proxy
-sm
5
--data-urlencode
"
${
payload
}
"
$url
-A
'zabbix-slack-alertscript / https://github.com/ericoc/zabbix-slack-alertscript'
)
# If the response body was not what was expected from Slack (
"ok"
), something went wrong so print the Slack error to stderr and exit with non-zero
if [[
"
$return
"
!=
'ok'
]]; then
>&2 echo
"
$return
"
exit 1
fi
> 출처 : https://github.com/jirouette/zabbix-mattermost-alertscript/blob/master/mattermost.py
```
python
#!/usr/bin/python
#coding: utf8
import
json
import
os
import
sys
import
requests
# Mattermost incoming web-hook URL and user name
URL
=
"<incoming webbook uri>"
# example: httpsL//mattermost.example.com/hooks/ere5h9gfbbbk8gdxsei1tt8ewewechjsd
USERNAME
=
"zabbix"
ICON
=
"<icon_url>"
LEVELS
=
[
"Warning"
,
"High"
,
"Disaster"
]
def
send_to_mattermost
(
webhook
,
channel
,
message
,
username
=
"zabbix"
,
color
=
"#FF2A00"
,
icon
=
""
,
highlight
=
False
):
# Build our JSON payload and send it as a POST request to the Mattermost incoming web-hook URL
payload
=
{
"icon_url"
:
icon
,
"attachments"
:
[{
"color"
:
color
,
"text"
:
message
}],
"channel"
:
channel
,
"username"
:
username
,
"icon_emoji"
:
""
}
if
highlight
:
payload
[
"message"
]
=
":warning: Cc <!here>"
requests
.
post
(
webhook
,
data
=
{
"payload"
:
json
.
dumps
(
payload
)})
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
<
4
:
print
(
"Usage: python "
+
sys
.
argv
[
0
]
+
" <CHANNEL> <SUBJECT> <MESSAGE>"
)
sys
.
exit
(
1
)
## Values received by this script:
# To = sys.argv[1] (Mattermost channel or user to send the message to, specified in the Zabbix web interface; "@username" or "#channel")
# Subject = sys.argv[2] (usually containing either "Problem" or "Resolved")
# Message = sys.argv[3] (whatever message the Zabbix action sends)
# Get the Mattermost channel or user (sys.argv[1]) and Zabbix subject (sys.argv[2])
channel
=
sys
.
argv
[
1
]
subject
=
sys
.
argv
[
2
]
if
"{{OK}}"
in
subject
:
subject
=
subject
.
replace
(
"{{OK}}"
,
":white_check_mark:"
)
elif
"{{WARNING}}"
in
subject
:
subject
=
subject
.
replace
(
"{{WARNING}}"
,
":warning:"
)
color
=
"#00FF13"
if
"Resolved"
in
subject
else
"#FF2A00"
# The message that we want to send to Mattermost is the "subject" value (sys.argv[2] / $subject - that we got earlier)
# followed by the message that Zabbix actually sent us (sys.argv[3])
message
=
"### "
+
subject
+
"
\n\n
"
+
sys
.
argv
[
3
]
# Let's highlight every connected people if the level is serious
highlight
=
False
for
level
in
LEVELS
:
if
level
in
message
:
highlight
=
True
break
# Send notification
send_to_mattermost
(
URL
,
channel
,
message
,
username
=
USERNAME
,
color
=
color
,
icon
=
ICON
,
highlight
=
highlight
)
```
-
Alert Example
![
zabbix_mattermost
](
./images/zabbix_mattermost.png
)
## Line Push Alert Script
```
bash
...
...
DOCKER/ZABBIX/images/zabbix_mattermost.png
0 → 100644
View file @
eef811f1
70.8 KB
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