-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckbeat.go
More file actions
85 lines (64 loc) · 1.67 KB
/
checkbeat.go
File metadata and controls
85 lines (64 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* attempt to write something to check if
* filebeat is "done" with a file
*
*/
package main
import (
"encoding/json"
"fmt"
"os"
"io/ioutil"
"golang.org/x/sys/unix"
)
/* Based on file beat 5.6 registry format */
type FileStateOS struct {
Inode uint64
Device uint64 /* devid num */
}
type FilebeatEntry struct {
Source string
Offset int64
FileStateOS FileStateOS
// Timestamp string /* we dont actually care about this yet */
// Ttl int /* meh */
}
var jsonbytes []byte
var regentries []FilebeatEntry
/* theoretical exit codes:
* 0 - file found and fully processed
* 1 - file found but NOT fully processed
* 2 - file not found
*/
func main() {
var Registrypath = "/var/lib/filebeat/registry"
if(len(os.Args) < 2) {
fmt.Println("Need a filename")
os.Exit(1)
}
targetfile := os.Args[1]
var targetstat unix.Stat_t
fmt.Println ("Debug: target file is ",targetfile)
unix.Lstat(targetfile, &targetstat)
fmt.Println ("Debug: dev, inode, length:",
targetstat.Dev, targetstat.Ino, targetstat.Size)
jsonbytes,_ := ioutil.ReadFile(Registrypath)
// jsonbytes,_ := ioutil.ReadFile("registry.json")
json.Unmarshal(jsonbytes, ®entries)
//fmt.Printf("All the strings\n")
//fmt.Printf("%+v",regentries)
for _, l := range regentries {
// fmt.Println( l.Source, l.Offset)
if((l.FileStateOS.Device == targetstat.Dev) && (l.FileStateOS.Inode == targetstat.Ino)) {
fmt.Println("File found in registry")
if(l.Offset == targetstat.Size){
fmt.Println("File is fully processed")
os.Exit(0)
} else {
fmt.Println("File ",targetfile," is NOT fully processed!")
os.Exit(1)
}
}
}
fmt.Println("File not found in registry!")
os.Exit(1)
}