Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/incident response #1

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
43 changes: 38 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {

// Read the configuration
config, err := readConfig(*configFile)
if err != nil {
if (err != nil) {
log.Fatalf("Error reading config: %v", err)
}

Expand All @@ -72,7 +72,7 @@ func main() {
var allKeys []string
for _, server := range config.MemcachedServers {
keys, err := getAllKeysFromMemcached(server)
if err != nil {
if (err != nil) {
log.Printf("Error getting keys from server %s: %v", server, err)
} else {
allKeys = append(allKeys, keys...)
Expand All @@ -88,8 +88,24 @@ func main() {
item, err := mc.Get(key)

if err != nil {
log.Printf("Error getting key %s: %v", key, err)
continue
if err == memcache.ErrCacheMiss {
// If cache miss, check all servers for the key
for _, server := range config.MemcachedServers {
mcSingle := memcache.New(server)
item, err = mcSingle.Get(key)
if err == nil {
log.Printf("Key %s found on server %s", key, server)
break
} else if err != memcache.ErrCacheMiss {
log.Printf("Error getting key %s from server %s: %v", key, server, err)
}
}
}

if err != nil {
log.Printf("Key %s not found on any server: %v", key, err)
continue
}
}

// Deserialize escaped JSON
Expand Down Expand Up @@ -119,8 +135,25 @@ func main() {
if created {
// Delete the key from Memcached if the incident was created successfully
err = mc.Delete(key)

if err != nil {
log.Printf("Error deleting key %s: %v", key, err)
if err == memcache.ErrCacheMiss {
// If cache miss, check all servers for the key
for _, server := range config.MemcachedServers {
mcSingle := memcache.New(server)
err = mcSingle.Delete(key)
if err == nil {
log.Printf("Successfully deleted key %s after creating incident", key)
break
} else if err != memcache.ErrCacheMiss {
log.Printf("Error getting key %s from server %s: %v", key, server, err)
}
}
}
if err != nil {
log.Printf("Error deleting key %s: %v", key, err)
continue
}
} else {
log.Printf("Successfully deleted key %s after creating incident", key)
}
Expand Down