Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fluentd-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ansible
Roles
fluentd-client
Commits
c23029e8
Commit
c23029e8
authored
6 years ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
Support for alerta alerts created from fluentd
parent
40c6abbc
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tasks/fluentd-client.yml
+9
-0
9 additions, 0 deletions
tasks/fluentd-client.yml
templates/alertalerta.py
+89
-0
89 additions, 0 deletions
templates/alertalerta.py
templates/td-agent.conf
+14
-0
14 additions, 0 deletions
templates/td-agent.conf
with
112 additions
and
0 deletions
tasks/fluentd-client.yml
+
9
−
0
View file @
c23029e8
...
...
@@ -69,6 +69,15 @@
tags
:
'
Config'
notify
:
"
Restart
td-agent"
-
name
:
"
Copy
script
to
post
Alerta"
template
:
src='alertalerta.py'
dest='/usr/local/bin/alertalerta.py'
owner='root'
group='root'
mode='755'
tags
:
'
Config'
-
name
:
"
Add
td-agent
user
to
adm
groups"
user
:
name='td-agent'
...
...
This diff is collapsed.
Click to expand it.
templates/alertalerta.py
0 → 100755
+
89
−
0
View file @
c23029e8
#!/usr/bin/env python
"""
Create an Alerta alert
======================
Alerts are unique with environment-resource-event
"""
import
argparse
import
json
import
os
import
time
from
subprocess
import
call
class
Alerta
:
args
=
None
extras
=
None
def
__init__
(
self
):
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
'
Alerta CLI
'
)
def
run
(
self
):
self
.
parser
.
add_argument
(
'
host
'
,
help
=
'
Host
'
)
self
.
parser
.
add_argument
(
'
environment
'
,
help
=
'
Environment
'
)
self
.
parser
.
add_argument
(
'
webhook
'
,
help
=
'
Alerta webhook
'
)
self
.
parser
.
add_argument
(
'
apikey
'
,
help
=
'
Alerta API key
'
)
self
.
parser
.
add_argument
(
'
payload
'
,
help
=
'
Json string or filename
'
)
self
.
args
,
self
.
extras
=
self
.
parser
.
parse_known_args
()
if
os
.
path
.
isfile
(
self
.
args
.
payload
):
fp
=
file
(
self
.
args
.
payload
)
for
line
in
fp
:
self
.
process
(
line
)
else
:
self
.
process
(
self
.
args
.
payload
)
def
default_values
(
self
):
values
=
{
'
origin
'
:
self
.
args
.
host
,
'
timeout
'
:
86400
,
'
environment
'
:
self
.
args
.
environment
,
'
resource
'
:
'
undefined-%s
'
%
time
.
time
(),
'
event
'
:
'
Exception
'
,
'
tags
'
:
[
'
environment:%s
'
%
self
.
args
.
environment
],
'
group
'
:
'
Application
'
,
'
severity
'
:
'
critical
'
,
'
service
'
:
[
'
www.example.com
'
],
'
text
'
:
''
,
'
value
'
:
''
,
'
rawData
'
:
''
,
}
return
values
@staticmethod
def
custom_keys
():
return
[
'
timeout
'
,
'
resource
'
,
'
event
'
,
'
severity
'
,
'
service
'
,
'
text
'
,
'
value
'
,
'
rawData
'
]
def
process
(
self
,
line
):
values
=
self
.
default_values
()
linevalues
=
json
.
loads
(
line
)
for
key
in
self
.
custom_keys
():
if
key
in
linevalues
.
keys
():
values
.
__setitem__
(
key
,
linevalues
[
key
])
cmd
=
[
'
/usr/bin/curl
'
,
'
-XPOST
'
,
'
%s/alert
'
%
self
.
args
.
webhook
,
'
-H
'
,
'
Authorization: Key %s
'
%
self
.
args
.
apikey
,
'
-H
'
,
'
Content-type: application/json
'
,
'
-d
'
,
json
.
dumps
(
values
)
]
call
(
cmd
)
Alerta
().
run
()
This diff is collapsed.
Click to expand it.
templates/td-agent.conf
+
14
−
0
View file @
c23029e8
...
...
@@ -27,6 +27,7 @@
format
json
port
{{
appl
.
port
}}
bind
127
.
0
.
0
.
1
message_length_limit
1
MB
</
source
>
{%
endfor
%}
...
...
@@ -192,6 +193,19 @@
pattern
\/
server
-
status
\?
auto
</
exclude
>
</
filter
>
<
match
alerta
>
@
type
exec
command
/
usr
/
local
/
bin
/
alertalerta
.
py
{{
inventory_hostname
}} {{
netdata_alerta_environment
|
default
(
"production"
) }} {{
netdata_alerta_webhook
}} {{
netdata_alerta_apikey
}}
<
buffer
>
@
type
file
path
/
var
/
log
/
td
-
agent
/
buffer
/
alerta
.*.
buffer
flush_at_shutdown
true
</
buffer
>
<
format
>
@
type
json
</
format
>
</
match
>
{%
if
fluentd_mail_output
is
defined
%}
<
match
mail
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment