aboutsummaryrefslogtreecommitdiff
path: root/pkg/zabbix/statefile.go
blob: 26ea6501eff59fb5bf09055ba92d838d366650e8 (plain)
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
package zabbix

import (
	"fmt"
	"os"
	"path/filepath"
)

const (
	bareosStateFile = "bareos-fd.9102.state"
	baculaStateFile = "bacula-fd.9102.state"
)

func checkStateFile() error {
	// Finds the state file to parse
	if stateFileName != "" {
		stateFileName = filepath.Join(workDir, stateFileName)
		info, err := os.Stat(stateFileName)
		if os.IsNotExist(err) || info.IsDir() {
			return fmt.Errorf("The state file %s does not exist", stateFileName)
		}
	} else {
		stateFileName = filepath.Join(workDir, bareosStateFile)
		info, err := os.Stat(stateFileName)
		if os.IsNotExist(err) || info.IsDir() {
			stateFileName = filepath.Join(workDir, baculaStateFile)
			info, err = os.Stat(stateFileName)
			if os.IsNotExist(err) || info.IsDir() {
				return fmt.Errorf("Could not find a suitable state file. Has a job ever run?")
			}
		}
	}
	return nil
}