gcwin

package module
v0.0.0-...-17bebec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2020 License: GPL-2.0 Imports: 24 Imported by: 0

README

gcwin

Test Status Coverage Status GoDoc

windows inventory collector agent.

Description

Installation

% go get github.com/getperf/gcwin

AUTHOR

Minoru Furusawa minoru.furusawa@toshiba.co.jp

Copyright 2019-2020, Minoru Furusawa, Toshiba digital solutions corporation.

LICENSE

This program is released under GNU General Public License, version 2.

Documentation

Index

Constants

View Source
const (
	DEFAULT_DISK_CAPACITY   int = 10
	DEFAULT_SAVE_HOUR           = 3
	DEFAULT_RECOVERY_HOUR       = 3
	DEFAULT_MAX_ERROR_LOG       = 10
	DEFAULT_COMMAND_TIMEOUT     = 86400
	LIMIT_MAX_ERROR_LOG         = 10000
	DEFAULT_PROXY_PORT          = 8080
	DEFAULT_LOG_LEVEL           = 3
	DEFAULT_LOG_SIZE            = 100000
	DEFAULT_LOG_ROTATION        = 5
	POLLER_INTERVAL             = 60
)

Default set fo gcwin.yaml

Variables

This section is empty.

Functions

func BackupConfig

func BackupConfig(srcDir string, targetDir string, filename string) error

BackupConfig は構成ファイルのバックアップをします。

func CheckDirectory

func CheckDirectory(path string) (bool, error)

CheckDirectory はディレクトリの存在確認をします。

func CheckFile

func CheckFile(path string) (bool, error)

CheckFile はファイルの存在確認をします。

func CheckProcess

func CheckProcess(pid int, keyword string) bool

github.com/mitchellh/go-ps 実装

func CopyFile

func CopyFile(srcPath, targetPath string) error

CopyFile はファイルのコピーをします。

func GetCurrentTime

func GetCurrentTime(sec int, dateFormat DateFormat) string

GetCurrentTime は指定したフォーマット形式で何秒前の現在時刻を取得します。

func GetHostname

func GetHostname() (string, error)

GetHostname はホスト名のエイリアスを取得します。

func GetHostnameAlias

func GetHostnameAlias(hostName string) (string, error)

GetHostnameAlias はホスト名の「.」以降の文字列はカットし、大文字は小文字に変換します。

func GetParentAbsPath

func GetParentAbsPath(inPath string, parentLevel int) (string, error)

GetParentPathAbs は実行パスから上位のディレクトリを絶対パスに変換して返します。

func GetParentPath

func GetParentPath(inPath string, parentLevel int) string

GetParentPathAbs は実行パスから上位のディレクトリを絶対パスに変換して返します。

func GetTimeString

func GetTimeString(dateFormat DateFormat, t time.Time) string

gpfDGetTimeString は指定したフォーマット形式で時刻を変換します。

GPF_DATE_FORMAT_DEFAULT         0
GPF_DATE_FORMAT_YYYYMMDD        1
GPF_DATE_FORMAT_HHMISS          2
GPF_DATE_FORMAT_YYYYMMDD_HHMISS 3
GPF_DATE_FORMAT_DIR             4

func MakeContext

func MakeContext(timeout int) (context.Context, context.CancelFunc)

func ReadFileHead

func ReadFileHead(filename string, maxRow int) ([]string, error)

ReadFile はファイルを指定した行数分読み込みます。

func Run

func Run(ctx context.Context, argv []string, stdout, stderr io.Writer) error

func TrimPathSeparator

func TrimPathSeparator(path string) string

TrimPathSeparator はパス名(/tmp/log/data/)から前後のセパレータを 取り除きます(tmp/log/data)

func Usage

func Usage(msgs *[]string)

Usage はヘルプメッセージを出力します。

Types

type Collector

type Collector struct {
	Id            int    /**< primary key(sequence) */
	StatName      string /**< Metric */
	Status        string
	StatEnable    bool /**< Enabled */
	Build         int  /**< Build version */
	StatStdoutLog bool /**< Standard output flag */
	StatInterval  int  /**< Interval(sec) */
	StatTimeout   int  /**< Timeout(sec) */
	NextTimestamp time.Time
	StatMode      string /**< Stataus mode */

	Jobs []*Job /**< First job */
}

func NewCollector

func NewCollector(statName string) *Collector

func (*Collector) AddJob

func (collector *Collector) AddJob(job *Job)

type CommandInfo

type CommandInfo struct {
	CmdLine string
	OutPath string
	Timeout int

	Executed bool
	Pid      int
	ExitCode int
	Status   string
	OutBuf   string
}

func (*CommandInfo) ExecCommandNoRedirect

func (c *CommandInfo) ExecCommandNoRedirect() error

func (*CommandInfo) ExecCommandNoRedirectWithContext

func (c *CommandInfo) ExecCommandNoRedirectWithContext(ctx context.Context) error

func (*CommandInfo) ExecCommandRedirect

func (c *CommandInfo) ExecCommandRedirect() error

func (*CommandInfo) ExecCommandRedirectWithContext

func (c *CommandInfo) ExecCommandRedirectWithContext(ctx context.Context) error

func (*CommandInfo) PeriodicLoopCommand

func (c *CommandInfo) PeriodicLoopCommand(ctx context.Context, cycle, step int) error

type Config

type Config struct {
	Module        int       // Module id(S:Scheduler, C:Collector, W:Worker)
	ElapseTime    int       // Elapsed time(sec)
	StartTime     time.Time // Start time(UTC)
	Mode          ProcMode  // Status(INIT, WAIT, RUN, ...)
	ManagedPid    int       // Scheduler process id
	DaemonFlag    int       // Daemon flag
	Host          string    // Hostname(Convert to lowercase , except the domain part)
	ServiceName   string    // HA service name
	Pwd           string    // Current directory
	Home          string    // Home directory
	ParameterFile string    // Parameter file
	ProgramName   string    // Program name
	ProgramPath   string    // Program path

	OutDir        string // Metric collection directory
	WorkDir       string // Work directory
	WorkCommonDir string // Common work directory
	ArchiveDir    string // Archive directory
	ScriptDir     string // Script directory
	BinDir        string // Binary directory
	LogDir        string // Application log directory

	ExitFlag string // Exit flag file
	PidFile  string // PID file
	PidPath  string // PID absolute path

	// SslConfig *soap.SSLConfig // struct  GPFSSLConfig_t  *sslConfig; // SSL manager
	// logConfig     *LogConfig  // struct  GPFLogConfig_t  *logConfig; // Log manager
	Schedule *Schedule // struct  GPFSchedule_t   *schedule;  // Scheduler
}

func NewConfig

func NewConfig(home string, configEnv *ConfigEnv) *Config

func (*Config) ArchiveData

func (config *Config) ArchiveData(task *Task, datastore *Datastore) error

ArchiveDataは、指定したタスクのログに対して zip 圧縮をします。 * arc_{host}__{stat}_{date}_{time}.zip ファイル名作成を作成します。 * {stat}/{date}/{time} ディレクトリパスを作成します。 * ログ保存ディレクトリ(ODir)に移動します。 * 次のコマンドと同じ zip 圧縮。zip -r arcxxx.zip ODIR

func (*Config) AuthLicense

func (config *Config) AuthLicense(expire int) error

func (*Config) CheckConfig

func (config *Config) CheckConfig() error

func (*Config) CheckDiskUtil

func (config *Config) CheckDiskUtil() error

func (*Config) CheckExitFile

func (config *Config) CheckExitFile() (string, error)

func (*Config) CheckHAStatus

func (config *Config) CheckHAStatus() error

func (*Config) CheckHostname

func (config *Config) CheckHostname(hostname string) bool

func (*Config) CheckLicense

func (config *Config) CheckLicense(expired int) error

CheckLicense はライセンスファイルをダウンロードし、ライセンスをチェックします

func (Config) CheckPathInHome

func (config Config) CheckPathInHome(path string) (bool, error)

CheckPathInHome はパスがホーム下を指定しているか、".."が含まれないかをチェックします。

func (*Config) CheckServiceExist

func (config *Config) CheckServiceExist(pid int) bool

func (Config) CheckWorkFile

func (config Config) CheckWorkFile(filename string) (bool, error)

CheckWorkFile はワークファイルの確認の有無を確認します。

func (*Config) DownloadLicense

func (config *Config) DownloadLicense() error

func (Config) GetArchivefilePath

func (config Config) GetArchivefilePath(filename string) string

func (*Config) GetCollector

func (config *Config) GetCollector(statName string) *Collector

func (*Config) GetServiceOrHostName

func (config *Config) GetServiceOrHostName() string

func (Config) GetWorkfilePath

func (config Config) GetWorkfilePath(filename string) string

GetWorkfilePath はファイル名が'_'で始まる場合は共有ディレクトリ下のパスを、 そうでない場合はローカルディレクトリ下のパスを返します。

func (*Config) InitAgent

func (c *Config) InitAgent() error

func (*Config) NewDatastore

func (c *Config) NewDatastore(statName string, start time.Time) (*Datastore, error)

func (*Config) NewDatastoreCurrent

func (c *Config) NewDatastoreCurrent(statName string) (*Datastore, error)

func (*Config) PostTask

func (config *Config) PostTask(task *Task)

func (*Config) PrepareCollector

func (config *Config) PrepareCollector(c *Collector) error

func (*Config) PurgeData

func (config *Config) PurgeData(task *Task, datastore *Datastore) error

func (Config) ReadPid

func (config Config) ReadPid() (int, error)

func (Config) ReadWorkFile

func (config Config) ReadWorkFile(filename string) ([]string, error)

ReadWorkFile はワークファイルを全行読み込みます。

func (Config) ReadWorkFileHead

func (config Config) ReadWorkFileHead(filename string, maxRow int) ([]string, error)

ReadWorkFile はワークファイルを指定した行数分読み込みます。

func (Config) ReadWorkFileNumber

func (config Config) ReadWorkFileNumber(filename string) (int, error)

ReadWorkFileNumber はワークファイルから数値を読み込みます。

func (Config) RemoveArchiveFile

func (config Config) RemoveArchiveFile(filename string) error

func (Config) RemoveWorkFile

func (config Config) RemoveWorkFile(filename string) error

RemoveWorkFile はワークファイルの削除をします。

func (*Config) Run

func (config *Config) Run() error

func (*Config) RunTask

func (config *Config) RunTask(c *Collector, count int, tasks chan<- *Task)

func (*Config) RunWithContext

func (config *Config) RunWithContext(ctx context.Context) error

func (*Config) SaveReport

func (config *Config) SaveReport(task *Task, datastore *Datastore) error

func (*Config) SendCollectorData

func (config *Config) SendCollectorData(zip string) error

func (*Config) SendCollectorDataAll

func (config *Config) SendCollectorDataAll(datastore *Datastore) error

func (*Config) Stop

func (config *Config) Stop() error

func (*Config) UnzipSSLConf

func (config *Config) UnzipSSLConf() error

func (Config) WriteLineWorkFile

func (config Config) WriteLineWorkFile(filename, line string) error

func (Config) WriteWorkFile

func (config Config) WriteWorkFile(filename string, lines []string) error

WriteWorkFile はークファイルの書き込みをします。

func (Config) WriteWorkFileNumber

func (config Config) WriteWorkFileNumber(filename string, num int) error

WriteWorkFileNumber はワークファイルへの数値の書き込みます。

type ConfigEnv

type ConfigEnv struct {
	// contains filtered or unexported fields
}

func NewConfigEnv

func NewConfigEnv() *ConfigEnv

NewCOnfigEnv は home を引数に設定情報を初期化します

func NewConfigEnvBase

func NewConfigEnvBase(host, program, config string) *ConfigEnv

type Datastore

type Datastore struct {
	StartTime time.Time
	StatName  string
	DateDir   string
	TimeDir   string
	OutDir    string
}

func NewDatastoreBase

func NewDatastoreBase(outDir, statName string, start time.Time) *Datastore

func (*Datastore) AbsDir

func (o *Datastore) AbsDir() string

func (*Datastore) InventoryZipFile

func (o *Datastore) InventoryZipFile(host string) string

func (*Datastore) OldZipFile

func (o *Datastore) OldZipFile(host string, hour int) string

func (*Datastore) RelDir

func (o *Datastore) RelDir() string

func (*Datastore) ZipFile

func (o *Datastore) ZipFile(host string) string

type DateFormat

type DateFormat int
const (
	DEFAULT DateFormat = iota
	YYYYMMDD
	HHMISS
	YYYYMMDD_HHMISS
	DIR
)

type DiskStatus

type DiskStatus struct {
	All  uint64 `json:"all"`
	Used uint64 `json:"used"`
	Free uint64 `json:"free"`
}

func CheckDiskFree

func CheckDiskFree(dir string) (DiskStatus, error)

CheckDiskFree は指定したディレクトリのディスク使用量[%]を取得します。

type Job

type Job struct {
	Id int /**< Primary key(sequence) */
	// Pid    int    /**< Worker process id */
	// Status int    /**< Process status */
	Cmd   string /**< Execute command */
	Ofile string /**< Output file */
	Cycle int    /**< Interval(sec) */
	Step  int    /**< Execute count */
}

func NewJob

func NewJob(id int, cmd string) *Job

type ProcMode

type ProcMode int
const (
	INIT ProcMode = iota
	WAIT
	RUN
	TIMEOUT
	END
	ERROR
)

type ReportTask

type ReportTask struct {
	Schedule ReportTaskTime
	Jobs     []ReportTaskJob
}

type ReportTaskJob

type ReportTaskJob struct {
	Id     int
	Out    string
	Cmd    string
	Start  time.Time
	End    time.Time
	Pid    int
	Rc     int
	Error  string
	Status string
}

type ReportTaskTime

type ReportTaskTime struct {
	Start time.Time
	End   time.Time
}

type Schedule

type Schedule struct {
	DiskCapacity int /**< Disk free threshold(%) */
	SaveHour     int /**< Metric data retention(H) */
	RecoveryHour int /**< Metric data retransmission(H) */
	MaxErrorLog  int /**< Max rows of error output */

	Pid    int /**< Scheduler process id */
	Status int /**< Process status */

	LogLevel     int  /**< Log level */
	DebugConsole bool /**< Console log enabled */
	LogSize      int  /**< Log size */
	LogRotation  int  /**< Number of log rotation */
	LogLocalize  bool /**< Flag of Japanese log */

	HanodeEnable bool   /**< HA node check flag */
	HanodeCmd    string /**< HA node check script */

	PostEnable bool   /**< Post command enabled */
	PostCmd    string /**< Post command */

	RemhostEnable bool   /**< Remote transfer enabled */
	UrlCM         string /**< Web service URL (Configuration manager) */
	UrlPM         string /**< Web service URL (Performance manager) */
	SoapTimeout   int    /**< Web service timeout */
	SiteKey       string /**< Site key */

	ProxyEnable bool   /**< HTTP proxy enabled */
	ProxyHost   string /**< Proxy host */
	ProxyPort   int    /**< Proxy port */

	LastUpdate  time.Time /**< Last update of parameter file */
	ParseFailed bool      /**< Set true if parser failed */

	Collectors map[string]*Collector // Collector pids
}

func NewSchedule

func NewSchedule() *Schedule

func (*Schedule) AddCollector

func (schedule *Schedule) AddCollector(collector *Collector)

func (*Schedule) FindOrCreateCollector

func (schedule *Schedule) FindOrCreateCollector(statName string) *Collector

func (*Schedule) GetCollector

func (schedule *Schedule) GetCollector(statName string) *Collector

type Task

type Task struct {
	Collector   *Collector
	Datastore   *Datastore
	Pid         int      /**< Collector process id */
	Status      ProcMode /**< Process status */
	StatTimeout int

	StartTime time.Time /**< Start time(UTC) */
	EndTime   time.Time /**< End time(UTC) */

	// DateDir   string /**< Date directory */
	// TimeDir   string /**< Time directory */
	Odir      string /**< Output directory */
	ScriptDir string /**< Script directory */
	TaskJobs  []*TaskJob
}

func NewTask

func NewTask(collector *Collector, odir, scriptDir string) *Task

func (*Task) MakeReport

func (t *Task) MakeReport() (string, error)

func (*Task) MakeReportTaskJobs

func (t *Task) MakeReportTaskJobs() []ReportTaskJob

func (*Task) Run

func (task *Task) Run() error

func (*Task) RunWithContext

func (task *Task) RunWithContext(ctx context.Context) error

type TaskJob

type TaskJob struct {
	Job       *Job
	Seq       int
	Timeout   int
	MaxRow    int
	Odir      string
	ScriptDir string
	CmdLine   string

	LoopCount   int
	CommandInfo *CommandInfo
	Status      ProcMode
	StartTime   time.Time
	EndTime     time.Time
}

func NewTaskJob

func NewTaskJob(seq int, job *Job, odir, scriptDir string) *TaskJob

func (*TaskJob) OutPath

func (taskJob *TaskJob) OutPath(ofile string) string

func (*TaskJob) Run

func (taskJob *TaskJob) Run() (*CommandInfo, error)

func (*TaskJob) RunWithContext

func (taskJob *TaskJob) RunWithContext(ctx context.Context) (*CommandInfo, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL