-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b038580
commit 3f2729a
Showing
13 changed files
with
301 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"checkingCommand": "cat /path/to/your/file.txt | tr -d '\n'", | ||
"interval": 5, | ||
"branchCommand": [ | ||
{ | ||
"resultExecution": "success", | ||
"commands": [ | ||
"echo 'Command executed successfully.'", | ||
"echo '' > /path/to/your/file.txt" | ||
] | ||
}, | ||
{ | ||
"resultExecution": "failure", | ||
"commands": [ | ||
"log_error", | ||
"send_alert" | ||
] | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
module github.com/SidorkinAlex/CyclicCommandCheckerAndExecutive | ||
|
||
go 1.21.9 | ||
|
||
require github.com/sevlyar/go-daemon v0.1.6 | ||
|
||
require ( | ||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect | ||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= | ||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= | ||
github.com/sevlyar/go-daemon v0.1.6 h1:EUh1MDjEM4BI109Jign0EaknA2izkOyi0LV3ro3QQGs= | ||
github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE= | ||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0= | ||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,7 @@ | ||
package Actions | ||
|
||
import ( | ||
"bufio" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/SidorkinAlex/CyclicCommandCheckerAndExecutive/internal/Config" | ||
"github.com/SidorkinAlex/CyclicCommandCheckerAndExecutive/internal/fileutils" | ||
"os" | ||
"strconv" | ||
"strings" | ||
) | ||
import "fmt" | ||
|
||
func CreateJob() { | ||
configPath := Config.ConfigPath | ||
config := Config.CreateConfig(configPath) | ||
|
||
reader := bufio.NewReader(os.Stdin) | ||
|
||
for { | ||
fmt.Println("1. Create a new command for monitoring") | ||
fmt.Println("2. Save changes and exit") | ||
fmt.Print("Choose an option: ") | ||
option, _ := reader.ReadString('\n') | ||
option = strings.TrimSpace(option) | ||
|
||
if option == "2" { | ||
break | ||
} | ||
|
||
if option == "1" { | ||
var newCommand Config.Command | ||
|
||
fmt.Print("Enter the command for cyclic execution and monitoring: ") | ||
command, _ := reader.ReadString('\n') | ||
newCommand.Command = strings.TrimSpace(command) | ||
|
||
fmt.Print("Enter the time interval in seconds for executing the above command: ") | ||
intervalStr, _ := reader.ReadString('\n') | ||
interval, err := strconv.Atoi(strings.TrimSpace(intervalStr)) | ||
if err != nil { | ||
fmt.Println("Invalid interval. Please enter a number.") | ||
continue | ||
} | ||
newCommand.Interval = interval | ||
|
||
for { | ||
fmt.Println("1. Add a new expected result") | ||
fmt.Println("2. Finish configuration and proceed to save") | ||
fmt.Print("Choose an option: ") | ||
resultOption, _ := reader.ReadString('\n') | ||
resultOption = strings.TrimSpace(resultOption) | ||
|
||
if resultOption == "2" { | ||
break | ||
} | ||
|
||
if resultOption == "1" { | ||
var branch Config.BranchResultExecution | ||
|
||
fmt.Print("Enter the expected result: ") | ||
result, _ := reader.ReadString('\n') | ||
branch.ResultExecution = strings.TrimSpace(result) | ||
|
||
for { | ||
fmt.Println("1. Enter a command to execute if the result matches") | ||
fmt.Println("2. Create a new expected result") | ||
fmt.Print("Choose an option: ") | ||
commandOption, _ := reader.ReadString('\n') | ||
commandOption = strings.TrimSpace(commandOption) | ||
|
||
if commandOption == "2" { | ||
break | ||
} | ||
|
||
if commandOption == "1" { | ||
fmt.Print("Enter the command to execute if the result matches: ") | ||
execCommand, _ := reader.ReadString('\n') | ||
branch.Commands = append(branch.Commands, strings.TrimSpace(execCommand)) | ||
} | ||
} | ||
|
||
newCommand.BranchCommand = append(newCommand.BranchCommand, branch) | ||
} | ||
} | ||
|
||
config = append(config, newCommand) | ||
} | ||
} | ||
|
||
// Display and save the new configuration | ||
configData, err := json.MarshalIndent(config, "", " ") | ||
if err != nil { | ||
fmt.Println("Error marshalling config:", err) | ||
return | ||
} | ||
|
||
fmt.Println("New configuration:") | ||
fmt.Println(string(configData)) | ||
|
||
fileutils.RewriteFile(string(configData), configPath) | ||
fmt.Println("Configuration saved successfully.") | ||
fmt.Println("this logic will appear in future versions") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package Actions | ||
|
||
func Restart() { | ||
import "fmt" | ||
|
||
func Restart() { | ||
fmt.Println("this logic will appear in future versions") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.