Fix lint errors, ensure errors start with 'hostname:'
This commit is contained in:
@ -4,7 +4,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"dario.cat/mergo"
|
||||
"gopkg.in/yaml.v3"
|
||||
@ -29,7 +29,7 @@ type Device struct {
|
||||
}
|
||||
|
||||
func readYAMLFile(path string) (map[string]interface{}, error) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -217,7 +217,9 @@ func main() {
|
||||
rootCmd.Flags().StringSliceVar(&hostFilter, "host", []string{}, "Specific host(s) to process (can be repeated, processes all if not specified)")
|
||||
rootCmd.Flags().IntVar(¶llel, "parallel", 10, "Maximum number of devices to process in parallel")
|
||||
|
||||
rootCmd.MarkFlagRequired("yaml")
|
||||
if err := rootCmd.MarkFlagRequired("yaml"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
log.Fatal(err)
|
||||
|
10
src/ssh.go
10
src/ssh.go
@ -4,7 +4,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -145,11 +144,11 @@ func (rb *RouterBackup) Connect() error {
|
||||
}
|
||||
}
|
||||
|
||||
key, err := ioutil.ReadFile(keyFile)
|
||||
key, err := os.ReadFile(keyFile)
|
||||
if err == nil {
|
||||
signer, err := ssh.ParsePrivateKey(key)
|
||||
if err != nil {
|
||||
fmt.Errorf("unable to parse private key: %v", err)
|
||||
fmt.Printf("%s: Unable to parse private key: %v\n", rb.hostname, err)
|
||||
} else {
|
||||
config.Auth = append(config.Auth, ssh.PublicKeys(signer))
|
||||
}
|
||||
@ -268,7 +267,10 @@ func (rb *RouterBackup) BackupCommands(commands []string, excludePatterns []stri
|
||||
|
||||
fmt.Fprintf(file, "## COMMAND: %s\n", command)
|
||||
filteredOutput := filterOutput(output, excludePatterns)
|
||||
file.WriteString(filteredOutput)
|
||||
if _, err := file.WriteString(filteredOutput); err != nil {
|
||||
fmt.Printf("%s: Failed to write output: %v\n", rb.hostname, err)
|
||||
hasErrors = true
|
||||
}
|
||||
file.Close()
|
||||
|
||||
successCount++
|
||||
|
Reference in New Issue
Block a user