Skip to content

Commit

Permalink
operating on users groups
Browse files Browse the repository at this point in the history
  • Loading branch information
kovetskiy committed Jun 27, 2016
1 parent 9ed002e commit ea4e1a4
Show file tree
Hide file tree
Showing 10 changed files with 599 additions and 162 deletions.
159 changes: 159 additions & 0 deletions docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package main

import "os"

var (
version = "2.0"
docs = `zabbixctl ` + version + os.ExpandEnv(`
zabbixctl is tool for working with zabbix server api using command line
interface, it provides effective way for operating on statuses of triggers and
hosts latest data.
zabbixctl must be configurated before using, configuration file should be
placed in ~/.config/zabbixctl.conf and must be written using following syntax:
[server]
address = "zabbix.local"
username = "admin"
password = "password"
[session]
path = "~/.cache/zabbixctl.session"
zabbixctl will authorize in 'zabbix.local' server using given user
credentials and save a zabbix session to a file ~/.cache/zabbixctl.session and
at second run will use saved session instead of new authorization, by the way
zabbix sessions have a ttl that by default equals to 15 minutes, so if saved
zabbix session is outdated, zabbixctl will repeat authorization and rewrite the
session file.
Usage:
zabbixctl [options] -T [/<pattern>...]
zabbixctl [options] -L <hostname>... [/<pattern>...]
zabbixctl -h | --help
zabbixctl --version
Workflow options:
-T --triggers
Search on zabbix triggers statuses. Triggers could be filtered using
/<pattern> argument, for example, search and acknowledge all triggers in a
problem state and match the word 'cache':
zabbixctl -Tp /cache
-k --only-nack
Show only not acknowledged triggers.
-x --severity
Specify minimum trigger severity. Once for information, twice for
warning, three for disaster, four for high, five for disaster.
-p --problem
Show triggers that have a problem state.
-r --recent
Show triggers that have recently been in a problem state.
-s --since <date>
Show triggers that have changed their state after the given time.
[default: 7 days ago]
-u --until <date>
Show triggers that have changed their state before the given time.
-m --maintenance
Show hosts in maintenance.
-i --sort <fields>
Show triggers sorted by specified fields.
[default: lastchange,priority]
-o --order <order>
Show triggers in specified order.
[default: DESC]
-n --limit <amount>
Show specified amount of triggers.
[default: 0]
-k --acknowledge
Acknowledge all retrieved triggers.
-f --noconfirm
Do not prompt acknowledge confirmation dialog.
-L --latest-data
Search and show latest data for specified host(s). Hosts can be searched
using wildcard character '*'. Latest data can be filtered using /<pattern>
argument, for example retrieve latest data for database nodes and search
information about replication:
zabbixctl -L dbnode-* /replication
-g --graph
Show links on graph pages.
-G --groups
Search and operate on configuration of users groups.
-l --list
Show list users in specified users group.
-a --add
Add specified <user> to specified users group.
-r --remove
Remove specified <user> from speicifed users group.
-f --noconfirm
Do not prompt confirmation dialog.
Misc options:
-c --config <path>
Use specified configuration file.
[default: $HOME/.config/zabbixctl.conf]
-v --verbosity Specify program output verbosity.
Once for debug, twice for trace.
-h --help
Show this screen.
--version
Show version.
`)
usage = `
zabbixctl [options] -T [-v]... [-x]... [<pattern>]...
zabbixctl [options] -L [-v]... <pattern>...
zabbixctl [options] -G [-v]... [<pattern>]...
zabbixctl [options] -G [-v]... <pattern>... -a <user>
zabbixctl [options] -G [-v]... <pattern>... -r <user>
zabbixctl -h | --help
zabbixctl --version
`
options = `
Options:
-T --triggers
-y --only-nack
-x --severity
-p --problem
-t --recent
-e --since <date> [default: 7 days ago]
-u --until <date>
-m --maintenance
-i --sort <fields> [default: lastchange,priority]
-o --order <order> [default: DESC]
-n --limit <amount> [default: 0]
-f --noconfirm
-k --acknowledge
-L --latest-data
-g --graph
-G --groups
-a --add <user>
-r --remove <user>
-c --config <path> [default: $HOME/.config/zabbixctl.conf]
-v --verbosity
-h --help
--version
`
)
43 changes: 29 additions & 14 deletions handle_latest_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,29 @@ func handleLatestData(
return errors.New("no hostname specified")
}

hosts, err := zabbix.GetHosts(
Params{
"monitored_hosts": "1",
"with_items": "1",
"with_monitored_items": "1",
"with_monitored_triggers": "1",
"search": Params{
"name": hostnames,
},
"searchWildcardsEnabled": "1",
"output": []string{
"host",
},
var hosts []Host
var err error

err = withSpinner(
":: Requesting information about hosts",
func() error {
hosts, err = zabbix.GetHosts(Params{
"monitored_hosts": "1",
"with_items": "1",
"with_monitored_items": "1",
"with_monitored_triggers": "1",
"search": Params{
"name": hostnames,
},
"searchWildcardsEnabled": "1",
"output": []string{
"host",
},
})
return err
},
)

if err != nil {
return hierr.Errorf(
err,
Expand All @@ -62,7 +70,14 @@ func handleLatestData(
"hostids": identifiers,
}

items, err := zabbix.GetItems(params)
var items []Item
err = withSpinner(
":: Requesting information about hosts items",
func() error {
items, err = zabbix.GetItems(params)
return err
},
)
if err != nil {
return hierr.Errorf(
err,
Expand Down
24 changes: 21 additions & 3 deletions handle_triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ func handleTriggers(
return err
}

triggers, err := zabbix.GetTriggers(params)
var triggers []Trigger

err = withSpinner(
":: Requesting information about statuses of triggers",
func() error {
triggers, err = zabbix.GetTriggers(params)
return err
},
)
if err != nil {
return hierr.Errorf(
err,
Expand Down Expand Up @@ -84,9 +92,19 @@ func handleTriggers(
}
}

err = zabbix.Acknowledge(identifiers)
err = withSpinner(
":: Acknowledging specified triggers",
func() error {
return zabbix.Acknowledge(identifiers)
},
)

if err != nil {
return err
return hierr.Errorf(
err,
"can't acknowledge triggers %s",
identifiers,
)
}

fmt.Fprintln(os.Stderr, ":: Acknowledged")
Expand Down
Loading

0 comments on commit ea4e1a4

Please sign in to comment.