Commit c2a15853 authored by nico baruna's avatar nico baruna

initatiate

parents
This source diff could not be displayed because it is too large. You can view the blob instead.
░░░░░░░░░░░░░░░░░░  ░█████╗░██╗░░██╗░█████╗░████████╗  ░░░░░░░░░░░░░░░░░░  
░░░░░░░░░░░░░░░░░░  ██╔══██╗██║░░██║██╔══██╗╚══██╔══╝  ░░░░░░░░░░░░░░░░░░  
█████╗█████╗█████╗  ██║░░╚═╝███████║███████║░░░██║░░░  █████╗█████╗█████╗  
╚════╝╚════╝╚════╝  ██║░░██╗██╔══██║██╔══██║░░░██║░░░  ╚════╝╚════╝╚════╝  
░░░░░░░░░░░░░░░░░░  ╚█████╔╝██║░░██║██║░░██║░░░██║░░░  ░░░░░░░░░░░░░░░░░░  
░░░░░░░░░░░░░░░░░░  ░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝░░░╚═╝░░░  ░░░░░░░░░░░░░░░░░░  
░██████╗███████╗██████╗░██╗░░░██╗███████╗██████╗░  ██████╗░███╗░░░███╗██████╗░
██╔════╝██╔════╝██╔══██╗██║░░░██║██╔════╝██╔══██╗  ██╔══██╗████╗░████║╚════██╗
╚█████╗░█████╗░░██████╔╝╚██╗░██╔╝█████╗░░██████╔╝  ██████╔╝██╔████╔██║░░███╔═╝
░╚═══██╗██╔══╝░░██╔══██╗░╚████╔╝░██╔══╝░░██╔══██╗  ██╔═══╝░██║╚██╔╝██║██╔══╝░░
██████╔╝███████╗██║░░██║░░╚██╔╝░░███████╗██║░░██║  ██║░░░░░██║░╚═╝░██║███████╗
╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚══════╝╚═╝░░╚═╝  ╚═╝░░░░░╚═╝░░░░░╚═╝╚══════╝
░░░░░░░██╗░░░░░░░██╗░█████╗░████████╗░█████╗░██╗░░██╗███████╗██████╗░░░░░░░
░░░░░░░██║░░██╗░░██║██╔══██╗╚══██╔══╝██╔══██╗██║░░██║██╔════╝██╔══██╗░░░░░░
█████╗░╚██╗████╗██╔╝███████║░░░██║░░░██║░░╚═╝███████║█████╗░░██████╔╝█████╗
╚════╝░░████╔═████║░██╔══██║░░░██║░░░██║░░██╗██╔══██║██╔══╝░░██╔══██╗╚════╝
░░░░░░░░╚██╔╝░╚██╔╝░██║░░██║░░░██║░░░╚█████╔╝██║░░██║███████╗██║░░██║░░░░░░
░░░░░░░░░╚═╝░░░╚═╝░░╚═╝░░╚═╝░░░╚═╝░░░░╚════╝░╚═╝░░╚═╝╚══════╝╚═╝░░╚═╝░░░░░░
\ No newline at end of file
module shell/tools/pm2
go 1.16
require (
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
)
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/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=
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
"time"
"gopkg.in/gomail.v2"
)
const CONFIG_SMTP_HOST = "Internalmail.banpuindo.co.id"
const CONFIG_SMTP_PORT = 25
const CONFIG_SENDER_NAME = "Nico Baruna <nico.baruna@gmail.com>"
const CONFIG_AUTH_EMAIL = "truckscale_app@banpuindo.co.id"
const CONFIG_AUTH_PASSWORD = ""
const MYFILE = "/var/www/webapps/caraka/.pm2/logs/CHaT-API-error.log"
const KEYWORD = "SequelizeConnectionAcquireTimeoutError"
var statSize int
func sendMail() {
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.SetAddressHeader("Cc", "dan@example.com", "Dan")
m.SetHeader("Subject", "Hello!")
m.SetBody("text/html", "Hello <b>Bob</b> and <i>Cora</i>!")
//m.Attach("/home/Alex/lolcat.jpg")
d := gomail.NewDialer(CONFIG_SMTP_HOST, CONFIG_SMTP_PORT, CONFIG_AUTH_EMAIL, CONFIG_AUTH_PASSWORD)
// Send the email to Bob, Cora and Dan.
if err := d.DialAndSend(m); err != nil {
panic(err)
}
log.Println("Mail sent!")
}
func banner() {
b, err := ioutil.ReadFile("banner.txt")
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
func main() {
banner()
//sendMail()
c := time.Tick(10 * time.Second)
statSize = 0
for _ = range c {
readFile(MYFILE)
}
}
func Native() string {
cmd, err := exec.Command("/bin/sh", "pm2 restart 0").Output()
if err != nil {
fmt.Printf("error %s", err)
}
output := string(cmd)
return output
}
func readFile(fname string) {
file, err := os.Open(fname)
if err != nil {
panic(err)
}
defer file.Close()
buf := make([]byte, 362)
stat, err := os.Stat(fname)
if statSize < int(stat.Size()) {
statSize = int(stat.Size())
start := stat.Size() - 362
_, err = file.ReadAt(buf, start)
if err == nil && strings.Contains(string(buf), KEYWORD) {
fmt.Printf("%s\n", buf)
fmt.Println("error found at " + time.Now().String())
fmt.Println(Native())
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment