Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
P
PM2 watcher
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Nico Baruna Putra
PM2 watcher
Commits
f36d5bae
Commit
f36d5bae
authored
Oct 25, 2021
by
Nico Baruna Putra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new way of checking log
parent
f4798650
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
46 deletions
+81
-46
CHaT-API-error1.log
CHaT-API-error1.log
+47
-14
go.mod
go.mod
+4
-0
go.sum
go.sum
+8
-0
index.go
index.go
+22
-32
No files found.
CHaT-API-error1.log
View file @
f36d5bae
This diff is collapsed.
Click to expand it.
go.mod
View file @
f36d5bae
...
...
@@ -3,6 +3,10 @@ module shell/tools/pm2
go 1.16
require (
github.com/hpcloud/tail v1.0.0 // indirect
golang.org/x/sys v0.0.0-20211020174200-9d6173849985 // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)
go.sum
View file @
f36d5bae
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
golang.org/x/sys v0.0.0-20211020174200-9d6173849985 h1:LOlKVhfDyahgmqa97awczplwkjzNaELFg3zRIJ13RYo=
golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df h1:n7WqCuqOuCbNr617RXOY0AWRXxgwEyPp2z+p0+hgMuE=
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkpBDuZnXENFzX8qRjMDMyPD6BRkCw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
index.go
View file @
f36d5bae
...
...
@@ -5,22 +5,21 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
"time"
"github.com/hpcloud/tail"
"gopkg.in/gomail.v2"
)
const
CONFIG_SMTP_HOST
=
"
I
nternalmail.banpuindo.co.id"
const
CONFIG_SMTP_HOST
=
"
i
nternalmail.banpuindo.co.id"
const
CONFIG_SMTP_PORT
=
25
const
CONFIG_SENDER_NAME
=
"Nico Baruna <nico
.baruna@gmail.com
>"
const
CONFIG_SENDER_NAME
=
"Nico Baruna <nico
_putra@banpuindo.co.id
>"
const
CONFIG_AUTH_EMAIL
=
"truckscale_app@banpuindo.co.id"
const
CONFIG_AUTH_PASSWORD
=
""
const
ShellToUse
=
"bash"
const
MYFILE
=
"
/var/www/webapps/caraka/.pm2/logs/CHaT-API-error
.log"
const
KEYWORD
=
"
SequelizeConnectionAcquireTimeoutError:
"
const
MYFILE
=
"
CHaT-API-error1
.log"
const
KEYWORD
=
"
ConnectionAcquireTimeoutError
"
var
statSize
int64
...
...
@@ -28,7 +27,7 @@ func sendMail(errorMsg string) {
fmt
.
Println
(
"Try sending email to "
+
CONFIG_SENDER_NAME
)
m
:=
gomail
.
NewMessage
()
m
.
SetHeader
(
"From"
,
"nico.baruna@gmail.com"
)
m
.
SetHeader
(
"To"
,
"nico.baruna@gmail.com"
,
"nico_putra@banpuindo.co.id"
)
m
.
SetHeader
(
"To"
,
"nico.baruna@gmail.com"
,
"nico_putra@banpuindo.co.id"
,
"manandit@gmail.com"
)
//m.SetAddressHeader("Cc", "dan@example.com", "Dan")
m
.
SetHeader
(
"Subject"
,
"Error found in Chat BE UAT!"
)
m
.
SetBody
(
"text/html"
,
"Hello <b>Nico</b> ! we found and error "
+
errorMsg
)
...
...
@@ -54,13 +53,7 @@ func banner() {
func
main
()
{
banner
()
//sendMail()
c
:=
time
.
Tick
(
10
*
time
.
Second
)
statSize
=
0
for
_
=
range
c
{
fmt
.
Println
(
"Start Scanning error log"
)
readFile
(
MYFILE
)
}
readFile
(
MYFILE
)
}
func
Shellout
(
command
string
)
(
error
,
string
,
string
)
{
...
...
@@ -85,25 +78,22 @@ func Native() {
}
func
readFile
(
fname
string
)
{
file
,
err
:=
os
.
Open
(
fname
)
if
err
!=
nil
{
panic
(
err
)
}
defer
file
.
Close
()
stat
,
err
:=
os
.
Stat
(
fname
)
buf
:=
make
([]
byte
,
int64
(
stat
.
Size
()))
if
statSize
<
int64
(
stat
.
Size
())
{
statSize
=
int64
(
stat
.
Size
())
start
:=
stat
.
Size
()
-
statSize
_
,
err
=
file
.
ReadAt
(
buf
,
start
)
if
err
==
nil
&&
strings
.
Contains
(
string
(
buf
),
KEYWORD
)
{
fmt
.
Println
(
"error found at "
+
time
.
Now
()
.
String
())
Native
()
sendMail
(
string
(
buf
))
t
,
err
:=
tail
.
TailFile
(
MYFILE
,
tail
.
Config
{
Follow
:
true
,
Poll
:
true
})
flag
:=
0
if
err
==
nil
{
for
line
:=
range
t
.
Lines
{
fmt
.
Println
(
"==NEW line detected=="
)
fmt
.
Println
(
line
.
Text
)
if
strings
.
Contains
(
line
.
Text
,
KEYWORD
)
{
fmt
.
Println
(
"ERROR FOUND"
)
Native
()
sendMail
(
line
.
Text
)
}
flag
++
fmt
.
Println
(
"end"
)
}
}
}
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