Package: humiocli
Do things with the Humio API from the command lineThis project requiresPython>=3.6.1This is a companion CLI to the unofficialhumioapilibrary. It lets you use most of its features easily from the command line. If you're looking for the official CLI it can be foundhere: humiolib.Installationpython3-mpipinstallhumiocli# or even betterpipxinstallhumiocliMain featuresStreaming searches with several output formatsSubsearches (pipe output from one search into a new search)Defaults configured through ENV variables (precedence:shell options>shell environment>config-file)Splunk-like chainable relative time modifiersSwitch easily from browser to CLI by passing the search URL to urlsearchIngest data to Humio (but you should use Filebeat for serious things)List repositoriesFirst time setupStart the guided setup wizard to configure your environmenthcwizardThis will help you create an environment file with a default Humio URL and token, so you don't have to explicitly provide them as options later.All options may be provided by environment variables on the formatHUMIO_<OPTION>=<VALUE>. If a .env file exists in~/.config/humio/.envit
will be automatically sourced on execution without overwriting the
existing environment.ExamplesExecute a search in all repos starting withreponameand output@rawstringshcsearch--repo'reponame*''#type=accesslog statuscode>=400'Execute a search using results with fields from another search ("subsearch")Step 1: Set the output format toor-fieldshcsearch--repo=auth'username | select([session_id, app_name])'--outformat=or-fields|jq'.'This gives a JSON-structure with prepared search strings from all field-value combinations. The special fieldSUBSEARCHcombines all search strings for all fields.Example output:{"session_id":"\"session_id\"=\"5CF4A111\" or \"session_id\"=\"14C8BCEA\"","app_name":"\"app_name\"=\"frontend\"","SUBSEARCH":"(\"session_id\"=\"5CF4A111\" or \"session_id\"=\"14C8BCEA\") and (\"app_name\"=\"frontend\")"}Step 2: Pipe this result to a new search and reference the desired fields:hcsearch--repo=auth'username | select([session_id, app_name])'--outformat=or-fields|hc--repo=frontend'#type=accesslog {{session_id}}'Output aggregated results as ND-JSON eventsSimple example:Humios bucketing currently creates partial buckets in both ends depending on search period. You may want to provide a rounded start and stop to ensure we only get whole buckets.hcsearch--repo'sandbox'--start=-60m@m--stop=@m"#type=accesslog | timechart(span=1m, series=statuscode)"Or with a longer multiline searchhcsearch--repo'sandbox'--start-60m@m--stop=@m"$(cat<< EOF#type=accesslog| case {statuscode<=400 | status_ok := 1 ;statuscode=4*  | status_client_error := "client_error" ;statuscode=5*  | status_server_error := "server_error" ;* | status_broken := 1}| bucket(limit=50, function=[count(as="count"), count(field=status_ok, as="ok"), count(field=status_client_error, as="client_error"), count(field=status_server_error, as="server_error")])| error_percentage := (((client_error + server_error) / count) * 100)EOF)"Upload a parser file to the destination repository, overwriting any existing parserhcmakeparser--repo='sandbox'customjsonIngest a single-line log file with an ingest-token associated with a parserhcingestcustomjsonIngest a multi-line file with a user provided record separator (markdown headers) and parserhcingestREADME.md--separator'^#'--fields'{"#repo":"sandbox", "#type":"markdown", "@host":"localhost"}'DevelopmentTo install the cli and api packages in editable mode:gitclonehttps://github.com/gwtwod/humiocli.git
poetryinstallCreate self-contained executables for easy distributionThis usesShivto create azipapp. A single self-contained file with all python dependencies and a shebang.On first run, this will unpack the required modues to~/.shiv/hc/which will cause a short delay in startup. Subsequent runs should be fast however. The location can be controlled with the env variableSHIV_ROOT. You should probably clean this directory once in a while, since a new one is created every time the distributable changes.pipinstallshiv
shiv-chc-ohchumiocli-p"/usr/bin/env python3"