Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
eth-log-alerting
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Server Tools
eth-log-alerting
Commits
f233de75
Commit
f233de75
authored
8 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
No more PHP dep!
parent
f593b6e6
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+0
-1
0 additions, 1 deletion
README.md
pipe.sh
+2
-2
2 additions, 2 deletions
pipe.sh
send.php
+0
-68
0 additions, 68 deletions
send.php
send.sh
+27
-0
27 additions, 0 deletions
send.sh
with
29 additions
and
71 deletions
README.md
+
0
−
1
View file @
f233de75
...
...
@@ -11,5 +11,4 @@ Pipe logs to Mattermost or Slack webhooks
*
Config file(s)
*
Init script with defaults override, restart, etc
*
Replace PHP script with straight bash script
*
Make binary deps paths configurable?
\ No newline at end of file
This diff is collapsed.
Click to expand it.
pipe.sh
+
2
−
2
View file @
f233de75
#!/bin/sh
tail
-Fq
log.log |
while
read
x
;
do
php im.php
"
$x
"
"#errors"
;
done
# TODO: path and config for send.sh
/usr/bin/
tail
-Fq
log.log |
while
read
x
;
do
send.sh
"
$x
"
"#errors"
"danger"
;
done
This diff is collapsed.
Click to expand it.
send.php
deleted
100644 → 0
+
0
−
68
View file @
f593b6e6
<?php
/**
* Parse log entry and format for webhook
*
* TODO: Switch to bash! This is a silly, vestigial implementation.
*
* @param string $message
* @param string $channel
* @param string $username
* @param string $icon_url
* @param string $webhook_url
* @return bool
*/
function
im
(
$message
=
''
,
$channel
=
'#errors'
,
$username
=
'Error Bot'
,
$icon_url
=
''
,
$webhook_url
)
{
if
(
!
is_string
(
$webhook_url
)
)
{
return
false
;
}
static
$counter
=
1
;
if
(
''
==
$message
)
{
$message
=
'debug '
.
$counter
;
$counter
++
;
}
elseif
(
is_array
(
$message
)
||
is_object
(
$message
)
)
{
$message
=
var_export
(
$message
,
true
);
}
// TODO: make an attachment?
$post_data
=
array
(
'channel'
=>
$channel
,
'username'
=>
$username
,
'icon_url'
=>
$icon_url
,
'text'
=>
"```
\n
{
$message
}
\n
```"
,
);
$curl
=
curl_init
();
$body
=
json_encode
(
$post_data
);
curl_setopt_array
(
$curl
,
array
(
CURLOPT_URL
=>
$webhook_url
,
CURLOPT_RETURNTRANSFER
=>
true
,
CURLOPT_ENCODING
=>
''
,
CURLOPT_FOLLOWLOCATION
=>
true
,
CURLOPT_TIMEOUT
=>
10
,
CURLOPT_CUSTOMREQUEST
=>
'POST'
,
CURLOPT_POSTFIELDS
=>
$body
,
CURLOPT_HTTPHEADER
=>
array
(
'Content-Type: application/json'
,
'Content-Length: '
.
strlen
(
$body
),
),
)
);
curl_exec
(
$curl
);
curl_close
(
$curl
);
return
true
;
}
$message
=
isset
(
$argv
[
1
]
)
?
$argv
[
1
]
:
null
;
$channel
=
isset
(
$argv
[
2
]
)
?
$argv
[
2
]
:
null
;
$username
=
isset
(
$argv
[
3
]
)
?
$argv
[
3
]
:
null
;
$icon_url
=
isset
(
$argv
[
4
]
)
?
$argv
[
4
]
:
null
;
$webhook_url
=
isset
(
$argv
[
5
]
)
?
$argv
[
5
]
:
null
;
im
(
$message
,
$channel
,
$username
,
$icon_url
,
$webhook_url
);
This diff is collapsed.
Click to expand it.
send.sh
0 → 100755
+
27
−
0
View file @
f233de75
#!/bin/sh
MSG
=
${
1
:-
Oops
}
CHANNEL
=
${
2
:-
#errors
}
COLOR
=
${
3
:-
default
}
# TODO: source these from a common config
USERNAME
=
"Log bot"
CONTEXT
=
"New log entry"
ICON_URL
=
""
WEBHOOK_URL
=
""
/usr/bin/curl
\
-X
POST
\
-s
\
--data-urlencode
"payload={
\
\"
channel
\"
:
\"
$CHANNEL
\"
,
\
\"
username
\"
:
\"
$USERNAME
\"
,
\
\"
attachments
\"
: [ {
\
\"
fallback
\"
:
\"
New log entry
\"
,
\
\"
pretext
\"
:
\"
$CONTEXT
\"
,
\
\"
text
\"
:
\"
$MSG
\"
,
\
\"
color
\"
:
\"
$COLOR
\"
\
} ],
\
\"
icon_url
\"
:
\"
$ICON_URL
\"
\
}"
\
$WEBHOOK_URL
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