Fix lint errors, ensure errors start with 'hostname:'
This commit is contained in:
@ -4,7 +4,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
|
|
||||||
"dario.cat/mergo"
|
"dario.cat/mergo"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@ -29,7 +29,7 @@ type Device struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readYAMLFile(path string) (map[string]interface{}, error) {
|
func readYAMLFile(path string) (map[string]interface{}, error) {
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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().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.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 {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
10
src/ssh.go
10
src/ssh.go
@ -4,7 +4,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -145,11 +144,11 @@ func (rb *RouterBackup) Connect() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
key, err := ioutil.ReadFile(keyFile)
|
key, err := os.ReadFile(keyFile)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
signer, err := ssh.ParsePrivateKey(key)
|
signer, err := ssh.ParsePrivateKey(key)
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
config.Auth = append(config.Auth, ssh.PublicKeys(signer))
|
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)
|
fmt.Fprintf(file, "## COMMAND: %s\n", command)
|
||||||
filteredOutput := filterOutput(output, excludePatterns)
|
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()
|
file.Close()
|
||||||
|
|
||||||
successCount++
|
successCount++
|
||||||
|
Reference in New Issue
Block a user