Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design2
/
2016104120
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Ma Suhyeon
2021-05-15 18:12:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
56213b2c64c2fa3b5780c0707bd8932dc3a2aa6c
56213b2c
1 parent
537b0450
Recover APIs
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
58 deletions
src/server/data.go
src/server/extraction.go
src/server/data.go
View file @
56213b2
...
...
@@ -4,11 +4,8 @@ import (
"context"
"fmt"
"net/http"
"strconv"
"strings"
"time"
"github.com/jmoiron/sqlx"
"github.com/labstack/echo/v4"
"github.com/olivere/elastic/v7"
...
...
@@ -231,80 +228,51 @@ func (app *App) GetMessagesAnalyses(c echo.Context) error {
}
type
Process
struct
{
UID
string
`json:"uid" db:"UID
"`
PID
int
`json:"pid" db:"PID
"`
PPID
int
`json:"ppid" db:"
PPID
"`
ST
IME
string
`json:"stime" db:"STIME
"`
T
IME
string
`json:"time" db:"TIME
"`
CMD
string
`json:"cmd" db:"
CMD
"`
PID
int
`json:"pid" db:"pid
"`
UID
string
`json:"uid" db:"uid
"`
PPID
int
`json:"ppid" db:"
ppid
"`
ST
ime
string
`json:"stime" db:"stime
"`
T
ime
string
`json:"time" db:"time
"`
CMD
string
`json:"cmd" db:"
cmd
"`
}
func
(
app
*
App
)
GetProcesses
(
c
echo
.
Context
)
error
{
processes
:=
[]
Process
{}
db
,
err
:=
sqlx
.
Connect
(
"sqlite3"
,
fmt
.
Sprintf
(
"data/1/%s"
,
c
.
Param
(
"file"
)))
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Could not open db file"
)
}
defer
db
.
Close
()
query
:=
`SELECT UID, CAST(PID AS INTEGER) PID, CAST(PPID AS INTEGER) PPID, STIME, TIME, CMD FROM process WHERE UID LIKE 'u%' ORDER BY TIME DESC`
db
.
Select
(
&
processes
,
query
)
query
:=
"SELECT * FROM processes WHERE `extraction_no`=? AND `uid` LIKE 'u%' ORDER BY `time` DESC"
fmt
.
Println
(
app
.
db
.
Unsafe
()
.
Select
(
&
processes
,
query
,
c
.
Param
(
"no"
))
)
return
c
.
JSON
(
http
.
StatusOK
,
processes
)
}
type
Alarm
struct
{
ID
string
`json:"id"`
When
time
.
Time
`json:"when"`
History
[]
AlarmHistory
`json:"history"`
ID
string
`json:"id"
db:"id"
`
When
time
.
Time
`json:"when"
db:"when"
`
History
[]
AlarmHistory
`json:"history"
db:"-"
`
}
type
AlarmHistory
struct
{
Type
string
`json:"type"`
When
time
.
Time
`json:"when"`
Type
string
`json:"type"
db:"type"
`
When
time
.
Time
`json:"when"
db:"when"
`
}
func
(
app
*
App
)
GetAlarms
(
c
echo
.
Context
)
error
{
db
,
err
:=
sqlx
.
Connect
(
"sqlite3"
,
fmt
.
Sprintf
(
"data/1/%s"
,
c
.
Param
(
"file"
)))
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Could not open db file"
)
}
defer
db
.
Close
()
alarms
:=
map
[
string
]
Alarm
{}
rows
,
_
:=
db
.
Queryx
(
"SELECT * FROM alarm ORDER BY TIME"
)
for
rows
.
Next
()
{
var
tm
string
var
typ
string
var
detail
string
rows
.
Scan
(
&
tm
,
&
typ
,
&
detail
)
alarms
:=
[]
Alarm
{}
query
:=
"SELECT * FROM alarms WHERE `extraction_no`=?"
detail
=
detail
[
strings
.
Index
(
detail
,
"{"
)
+
1
:
strings
.
Index
(
detail
,
"}"
)]
s
:=
strings
.
Split
(
detail
,
" "
)
timestamp
,
_
:=
strconv
.
ParseInt
(
s
[
4
],
10
,
64
)
timestamp
/=
1000
if
_
,
ok
:=
alarms
[
s
[
0
]];
!
ok
{
alarms
[
s
[
0
]]
=
Alarm
{
ID
:
s
[
0
],
When
:
time
.
Unix
(
timestamp
,
0
)}
}
when
,
_
:=
time
.
Parse
(
"2006-01-02 15:04:05"
,
tm
)
alarm
:=
alarms
[
s
[
0
]]
alarm
.
History
=
append
(
alarms
[
s
[
0
]]
.
History
,
AlarmHistory
{
Type
:
typ
,
When
:
when
,
})
alarms
[
s
[
0
]]
=
alarm
extNo
:=
c
.
Param
(
"no"
)
if
err
:=
app
.
db
.
Unsafe
()
.
Select
(
&
alarms
,
query
,
extNo
);
err
!=
nil
{
return
err
}
results
:=
[]
Alarm
{}
for
_
,
v
:=
range
alarms
{
results
=
append
(
results
,
v
)
query
=
"SELECT * FROM alarm_histories WHERE `extraction_no`=? AND `id`=?"
for
i
:=
range
alarms
{
if
err
:=
app
.
db
.
Unsafe
()
.
Select
(
&
alarms
[
i
]
.
History
,
query
,
extNo
,
alarms
[
i
]
.
ID
);
err
!=
nil
{
return
err
}
}
return
c
.
JSON
(
http
.
StatusOK
,
result
s
)
return
c
.
JSON
(
http
.
StatusOK
,
alarm
s
)
}
type
Schedule
struct
{
...
...
src/server/extraction.go
View file @
56213b2
...
...
@@ -8,6 +8,9 @@ import (
"net/http"
"os"
"os/exec"
"strconv"
"strings"
"time"
"github.com/dgrijalva/jwt-go"
"github.com/jmoiron/sqlx"
...
...
@@ -138,7 +141,7 @@ func (app *App) PostExtractions(c echo.Context) error {
}
}
/*
alarms := map[string]Alarm{}
alarms
:=
map
[
string
]
Alarm
{}
rows
,
_
=
db
.
Queryx
(
"SELECT * FROM alarm ORDER BY TIME"
)
for
rows
.
Next
()
{
...
...
@@ -172,7 +175,7 @@ func (app *App) PostExtractions(c echo.Context) error {
for
_
,
h
:=
range
v
.
History
{
tx
.
Exec
(
"INSERT INTO alarm_histories VALUES (?, ?, ?, ?)"
,
extNo
,
v
.
ID
,
h
.
Type
,
h
.
When
)
}
}
*/
}
tx
.
Commit
()
...
...
Please
register
or
login
to post a comment