Skip to content
Mirror of the zc-portable project
C Roff Other
Branch: master
Clone or download

Latest commit

absc
Latest commit e8df375 Mar 29, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
m4 Invert linker arguments. Mar 22, 2020
man Regen. Mar 22, 2020
zc Corrected wrong installation dir. Feb 8, 2020
zcapplication Remove the BSD Makefiles. Feb 8, 2020
zcapplicationadd Remove the BSD Makefiles. Feb 8, 2020
zcapplicationget Remove the BSD Makefiles. Feb 8, 2020
zcapplicationrm Remove the BSD Makefiles. Feb 8, 2020
zcauth Remove the BSD Makefiles. Feb 8, 2020
zcconfig Remove the BSD Makefiles. Feb 8, 2020
zcconfigexport Remove the BSD Makefiles. Feb 8, 2020
zcconfigexporthost Remove the BSD Makefiles. Feb 8, 2020
zcconfigexporthostgroup Remove the BSD Makefiles. Feb 8, 2020
zcconfigexportimage Remove the BSD Makefiles. Feb 8, 2020
zcconfigexportmap Remove the BSD Makefiles. Feb 8, 2020
zcconfigexportscreen Remove the BSD Makefiles. Feb 8, 2020
zcconfigexporttemplate Remove the BSD Makefiles. Feb 8, 2020
zcconfigexportvaluemap Remove the BSD Makefiles. Feb 8, 2020
zcconfigimport Remove the BSD Makefiles. Feb 8, 2020
zcevent
zceventget Remove the BSD Makefiles. Feb 8, 2020
zchistory Remove the BSD Makefiles. Feb 8, 2020
zchistorychar Remove the BSD Makefiles. Feb 8, 2020
zchistoryfloat Remove the BSD Makefiles. Feb 8, 2020
zchistorylog Remove the BSD Makefiles. Feb 8, 2020
zchistorynum Remove the BSD Makefiles. Feb 8, 2020
zchost Remove the BSD Makefiles. Feb 8, 2020
zchostadd Remove the BSD Makefiles. Feb 8, 2020
zchostdisable Remove the BSD Makefiles. Feb 8, 2020
zchostenable Remove the BSD Makefiles. Feb 8, 2020
zchostget Remove the BSD Makefiles. Feb 8, 2020
zchostgroup Remove the BSD Makefiles. Feb 8, 2020
zchostgroupadd Remove the BSD Makefiles. Feb 8, 2020
zchostgroupget Remove the BSD Makefiles. Feb 8, 2020
zchostgrouprm Remove the BSD Makefiles. Feb 8, 2020
zchostinterface Remove the BSD Makefiles. Feb 8, 2020
zchostinterfaceadd Remove the BSD Makefiles. Feb 8, 2020
zchostinterfaceget Remove the BSD Makefiles. Feb 8, 2020
zchostinterfacerm Remove the BSD Makefiles. Feb 8, 2020
zchostrm Remove the BSD Makefiles. Feb 8, 2020
zcitem Remove the BSD Makefiles. Feb 8, 2020
zcitemadd Remove the BSD Makefiles. Feb 8, 2020
zcitemaddactive Remove the BSD Makefiles. Feb 8, 2020
zcitemaddpassive Remove the BSD Makefiles. Feb 8, 2020
zcitemaddsimple Remove the BSD Makefiles. Feb 8, 2020
zcitemaddtrapper Remove the BSD Makefiles. Feb 8, 2020
zcitemdisable Remove the BSD Makefiles. Feb 8, 2020
zcitemenable Remove the BSD Makefiles. Feb 8, 2020
zcitemget
zcitemrm Remove the BSD Makefiles. Feb 8, 2020
zclose Remove the BSD Makefiles. Feb 8, 2020
zcproblem Remove the BSD Makefiles. Feb 8, 2020
zcproblemack Remove the BSD Makefiles. Feb 8, 2020
zcproblemannotate Remove the BSD Makefiles. Feb 8, 2020
zcproblemclose Remove the BSD Makefiles. Feb 8, 2020
zcproblemescalate Remove the BSD Makefiles. Feb 8, 2020
zcproblemget Remove the BSD Makefiles. Feb 8, 2020
zcproxy Remove the BSD Makefiles. Feb 8, 2020
zcproxyadd Remove the BSD Makefiles. Feb 8, 2020
zcproxyget Remove the BSD Makefiles. Feb 8, 2020
zcproxyrm Remove the BSD Makefiles. Feb 8, 2020
zctemplate Remove the BSD Makefiles. Feb 8, 2020
zctemplateadd Remove the BSD Makefiles. Feb 8, 2020
zctemplateget Remove the BSD Makefiles. Feb 8, 2020
zctemplaterm Remove the BSD Makefiles. Feb 8, 2020
zctrigger Remove the BSD Makefiles. Feb 8, 2020
zctriggeradd Remove the BSD Makefiles. Feb 8, 2020
zctriggerget Remove the BSD Makefiles. Feb 8, 2020
zctriggerrm Remove the BSD Makefiles. Feb 8, 2020
CHANGELOG Updated CHANGELOG. Jan 16, 2020
README.md Add clarifications about the license. Mar 29, 2020
common.c Add initial macro support. Feb 9, 2020
common.h Initial revision Jan 16, 2020
compat.h Add initial FreeBSD support. Mar 5, 2020
defines.h Initial revision Jan 16, 2020
execvpe.c Add initial FreeBSD support. Mar 5, 2020
explicit_bzero.c Add explicit_bzero(3) for linux. Feb 15, 2020
getprogname.c Add basic support for getprogname() for linux. Feb 15, 2020
jsmn.c Initial revision Jan 16, 2020
jsmn.h Initial revision Jan 16, 2020
mkgen.sh Add initial FreeBSD support. Mar 5, 2020
pathnames.h Initial revision Jan 16, 2020
pledge.c stdef.h -> stddef.h Feb 16, 2020
reallocarray.c Add the reallocarray(3) implementation. Feb 15, 2020
strlcpy.c Include compat.h, required for the prototypes. Feb 15, 2020
strtonum.c Include compat.h, required for the prototypes. Feb 15, 2020
targets.txt Added the targets file. Feb 3, 2020
unveil.c stdef.h -> stddef.h Feb 16, 2020
zc-application-add.1 Initial revision Jan 16, 2020
zc-application-get.1 Initial revision Jan 16, 2020
zc-application-rm.1 Initial revision Jan 16, 2020
zc-application.1 Initial revision Jan 16, 2020
zc-auth.1 Initial revision Jan 16, 2020
zc-close.1 Initial revision Jan 16, 2020
zc-config-export-host.1 Initial revision Jan 16, 2020
zc-config-export-hostgroup.1 Initial revision Jan 16, 2020
zc-config-export-image.1 Initial revision Jan 16, 2020
zc-config-export-map.1 Initial revision Jan 16, 2020
zc-config-export-screen.1 Initial revision Jan 16, 2020
zc-config-export-template.1 Initial revision Jan 16, 2020
zc-config-export-valuemap.1 Initial revision Jan 16, 2020
zc-config-export.1 Initial revision Jan 16, 2020
zc-config-import.1 Initial revision Jan 16, 2020
zc-config.1 Initial revision Jan 16, 2020
zc-event-get.1 Initial revision Jan 16, 2020
zc-event.1 Initial revision Jan 16, 2020
zc-history-char.1 Initial revision Jan 16, 2020
zc-history-float.1 Initial revision Jan 16, 2020
zc-history-log.1 Initial revision Jan 16, 2020
zc-history-num.1 Initial revision Jan 16, 2020
zc-history.1 Initial revision Jan 16, 2020
zc-host-add.1 Initial revision Jan 16, 2020
zc-host-disable.1
zc-host-enable.1 Initial revision Jan 16, 2020
zc-host-get.1 Initial revision Jan 16, 2020
zc-host-interface-add.1 Initial revision Jan 16, 2020
zc-host-interface-get.1 Initial revision Jan 16, 2020
zc-host-interface-rm.1 Initial revision Jan 16, 2020
zc-host-interface.1 Initial revision Jan 16, 2020
zc-host-rm.1 Initial revision Jan 16, 2020
zc-host.1 Initial revision Jan 16, 2020
zc-hostgroup-add.1 Initial revision Jan 16, 2020
zc-hostgroup-get.1 Initial revision Jan 16, 2020
zc-hostgroup-rm.1 Initial revision Jan 16, 2020
zc-hostgroup.1 Initial revision Jan 16, 2020
zc-intro.7 Add clarifications about the license. Mar 29, 2020
zc-item-add-active.1 Initial revision Jan 16, 2020
zc-item-add-passive.1 Initial revision Jan 16, 2020
zc-item-add-simple.1 Initial revision Jan 16, 2020
zc-item-add-trapper.1 Initial revision Jan 16, 2020
zc-item-add.1 Initial revision Jan 16, 2020
zc-item-disable.1 Initial revision Jan 16, 2020
zc-item-enable.1 Initial revision Jan 16, 2020
zc-item-get.1 Initial revision Jan 16, 2020
zc-item-rm.1 Initial revision Jan 16, 2020
zc-item.1 Initial revision Jan 16, 2020
zc-problem-ack.1 Initial revision Jan 16, 2020
zc-problem-annotate.1 Initial revision Jan 16, 2020
zc-problem-close.1 Initial revision Jan 16, 2020
zc-problem-escalate.1 Initial revision Jan 16, 2020
zc-problem-get.1 Initial revision Jan 16, 2020
zc-problem.1 Initial revision Jan 16, 2020
zc-proxy-add.1 Initial revision Jan 16, 2020
zc-proxy-get.1 Initial revision Jan 16, 2020
zc-proxy-rm.1 Initial revision Jan 16, 2020
zc-proxy.1 Initial revision Jan 16, 2020
zc-template-add.1 Initial revision Jan 16, 2020
zc-template-get.1 Initial revision Jan 16, 2020
zc-template-rm.1 Initial revision Jan 16, 2020
zc-template.1 Initial revision Jan 16, 2020
zc-trigger-add.1 Initial revision Jan 16, 2020
zc-trigger-get.1 Initial revision Jan 16, 2020
zc-trigger-rm.1 Initial revision Jan 16, 2020
zc-trigger.1 Initial revision Jan 16, 2020
zc.1 Initial revision Jan 16, 2020
zc.c Add initial macro support. Feb 9, 2020
zcapplication.c Add initial macro support. Feb 9, 2020
zcapplicationadd.c Add initial macro support. Feb 9, 2020
zcapplicationget.c Add initial macro support. Feb 9, 2020
zcapplicationrm.c Add initial macro support. Feb 9, 2020
zcauth.c When we receive a response from the zabbix API about Mar 23, 2020
zcconfig.c Add initial macro support. Feb 9, 2020
zcconfigexport.c Add missing initializer. Mar 5, 2020
zcconfigexporthost.c Add initial macro support. Feb 9, 2020
zcconfigexporthostgroup.c Add initial macro support. Feb 9, 2020
zcconfigexportimage.c Add initial macro support. Feb 9, 2020
zcconfigexportmap.c Add initial macro support. Feb 9, 2020
zcconfigexportscreen.c Add initial macro support. Feb 9, 2020
zcconfigexporttemplate.c Add initial macro support. Feb 9, 2020
zcconfigexportvaluemap.c Add initial macro support. Feb 9, 2020
zcconfigimport.c Add initial macro support. Feb 9, 2020
zcevent.c Add initial macro support. Feb 9, 2020
zceventget.c Add initial macro support. Feb 9, 2020
zchistory.c Add initial macro support. Feb 9, 2020
zchistorychar.c Add initial macro support. Feb 9, 2020
zchistoryfloat.c Add initial macro support. Feb 9, 2020
zchistorylog.c Add initial macro support. Feb 9, 2020
zchistorynum.c Add initial macro support. Feb 9, 2020
zchost.c Add initial macro support. Feb 9, 2020
zchostadd.c Add initial macro support. Feb 9, 2020
zchostdisable.c Add initial macro support. Feb 9, 2020
zchostenable.c Add initial macro support. Feb 9, 2020
zchostget.c Add initial macro support. Feb 9, 2020
zchostgroup.c Add missing initializer. Mar 5, 2020
zchostgroupadd.c Add initial macro support. Feb 9, 2020
zchostgroupget.c Add initial macro support. Feb 9, 2020
zchostgrouprm.c Add initial macro support. Feb 9, 2020
zchostinterface.c Add initial macro support. Feb 9, 2020
zchostinterfaceadd.c Add initial macro support. Feb 9, 2020
zchostinterfaceget.c Add initial macro support. Feb 9, 2020
zchostinterfacerm.c Add initial macro support. Feb 9, 2020
zchostrm.c Add initial macro support. Feb 9, 2020
zcitem.c Add initial macro support. Feb 9, 2020
zcitemadd.c Add initial macro support. Feb 9, 2020
zcitemaddactive.c Add initial macro support. Feb 9, 2020
zcitemaddpassive.c Add initial macro support. Feb 9, 2020
zcitemaddsimple.c Add initial macro support. Feb 9, 2020
zcitemaddtrapper.c Add initial macro support. Feb 9, 2020
zcitemdisable.c Add initial macro support. Feb 9, 2020
zcitemenable.c Add initial macro support. Feb 9, 2020
zcitemget.c Add initial macro support. Feb 9, 2020
zcitemrm.c
zclose.c Add initial macro support. Feb 9, 2020
zcproblem.c Add initial macro support. Feb 9, 2020
zcproblemack.c Add initial macro support. Feb 9, 2020
zcproblemannotate.c Add initial macro support. Feb 9, 2020
zcproblemclose.c Add initial macro support. Feb 9, 2020
zcproblemescalate.c Add initial macro support. Feb 9, 2020
zcproblemget.c Check if the given severity is valid. Mar 18, 2020
zcproxy.c Add initial macro support. Feb 9, 2020
zcproxyadd.c Remove unused variable. Feb 16, 2020
zcproxyget.c Properly terminate main(). Feb 16, 2020
zcproxyrm.c Add initial macro support. Feb 9, 2020
zctemplate.c Add initial macro support. Feb 9, 2020
zctemplateadd.c Add initial macro support. Feb 9, 2020
zctemplateget.c Add initial macro support. Feb 9, 2020
zctemplaterm.c Add initial macro support. Feb 9, 2020
zctrigger.c Add initial macro support. Feb 9, 2020
zctriggeradd.c Add initial macro support. Feb 9, 2020
zctriggerget.c Add initial macro support. Feb 9, 2020
zctriggerrm.c Add initial macro support. Feb 9, 2020
zrpc.c When we receive a response from the zabbix API about Mar 23, 2020
zrpc.h Use long long instead of int64_t. Feb 16, 2020

README.md

NAME

zc-intro - introduction to the zc command line tools

DESCRIPTION

Working with the zabbix APIs without resorting to the usage of powerful tools like python or perl can be difficult. However, day to day tasks, like closing a series of problems, or fetching some history values, should not be difficult because of that.

zc(1) represents a series of commands, written in C, that make heavy use of the canonical UNIX shell facilities (pipes etc..) for integrating the zabbix APIs in a shell environment. The main design goal of the zc(1) commands, is to be usable in conjunction of powerful tools like awk(1) and with more canonical tools such as grep(1) and cut(1).

It must be noted that zc(1) is NOT a replacement for the flexibility of using the zabbix APIs with a powerful programming language like perl(1), but it is meant to make the most common tasks easily scriptable.

LICENSE

The project is released under the ISC license

DESIGN

zc(1) is composed by a main command (the entry point), with a series of sub commands, meant to perform only one task. All the sub commands can be called independently, thus allowing, in a future, scenarios where more high level commands can combine, themselves, different zc(1) sub commands if required.

All the sub commands are implemented as different binaries, and they share a common set of code that handle the JSON rpc part with a zabbix web frontend.

Allowing sessions to be started and terminated, for example on a cron job, is done by saving the authentication token and the related http URL in the user's home directory, for being used by subsequent requests.

Another main design decision, was to decide if a command could perform different configuration change operations, like acknowledging and closing a problem with the same binary. From a semantic point of view, it was decided that, instead of cluttering sub commands with different flags, a main modification operation must be implemented by another command, even if they call the same API. combining different actions, is done by properly allowing the sub commands to work in pipelines. For example, the following one-liner:

$ zc problem get -b 2019-02-18T00:00:00 | cut -f 1 |
    zc problem ack -m "acknowledged" | zc problem close

will:

  • Fetch all the problems opened after February 18, 2019.
  • Acknowledge all the problems with a message "acknowledged".
  • Close all the problems.

DEPENDENCIES

zc(1) depends on:

  • A C compiler (gcc and clang are supported)
  • libcurl
  • m4
  • make

INSTALLATION

If it doesn't exist, create the zc directory for the command binaries under /usr/local/libexec. and the man page directories under /usr/local/man/man1 and /usr/local/man/man7

# mkdir -p /usr/local/libexec/zc
# mkdir -p /usr/local/man/man1
# mkdir -p /usr/local/man/man7
# chown root:wheel /usr/local/libexec/zc
# chmod 0755 /usr/local/libexec/zc

After extracting the tar.gz file, from inside the project directory:

$ ./mkgen.sh
$ make
# make install

Currently, zc-portable works on:

  • OpenBSD
  • FreeBSD
  • RHEL/CentOS 7
  • Debian/Ubuntu
  • Alpine linux

KNOWN ISSUES

  • On Debian and derivatives, /bin/sh is symlinked to dash. This causes an error with a condition in the ./mkgen.sh script.

    To avoid the problem, call the script with bash instead:

    $ bash ./mkgen.sh
    
  • Alpine linux uses the musl libc by default. This means the sys/cdefs.h header doesn't exists in a standard installation. To compile zc-portable(1) you need to install the libbsd and libbsd-dev packages:

    # apk add libbsd libbsd-dev
    

BASIC USAGE

The first thing to do, is authenticating zc(1) with a zabbix server. We store the authentication informations in the "prod" authentication context. If no context is specified, "default" is used:

$ zc -c prod auth -u user -p password http[s]://server/api_jsonrpc.php

Where the path is the full URL to the zabbix APIs php file (as described in the zabbix documentation).

If the authentication is successful, it will be possible to perform operations like:

$ zc -c prod host get
10084	enabled	unavailable	Zabbix server

for retrieving the list of all monitored hosts or:

$ export ZC_CTX=prod
$ zc item add passive -d 1m -h 10326 -i 59 \
    -n "Number of running processes" -s 7d -r 365d \
    -t num 'proc.nump[]'
31922
$ zc item get -h 'Zabbix server' 'Number of running processes'
31922   10326   1m      proc.nump[]     Number of running processes

For creating a new zabbix agent passive check. In the example, the item is a check named "Number of running processes" with a history and trends retention period of 7 and 365 days, part of the host with id 10326 of type unsigned number.

We exported the "prod" context first, thus setting it as the default one in the current shell, without the need to specify it on the command line every time.

After the monitoring start to collect data, it's possible to fetch data for a particular item:

$ zc history float -s 2019-04-01T00:00:00 31922
31922	1554132473	0.5370	152883791
31922	1554132533	0.5280	753532397
31922	1554132593	0.5370	342977311
31922	1554132653	0.5281	943250782
31922	1554132713	0.5370	533437503
31922	1554132773	0.5370	123361077
31922	1554132833	0.5281	723530353
31922	1554132893	0.5538	313831844
31922	1554132953	0.5116	913494776
31922	1554133013	0.5370	504180284

Once done, closing the session in the exported "prod" context is easy:

$ zc close

Or if we didn't exported it:

$ zc -c prod close

Every sub command, have it's own man page, so it's easy to learn how to use all the implemented commands.

SEE ALSO

zc(1)

AUTHORS

Andrea Biscuola <a@abiscuola.com>

You can’t perform that action at this time.