Icinga / icingaweb2-module-cube

Drill-down view for Icinga web 2 based on custom variables
GNU General Public License v2.0
45 stars 12 forks source link

CLI commands for host and service status by dimension(s) #19

Open kobmaki opened 7 years ago

kobmaki commented 7 years ago

Implement the missing cli command for the cube hoststatus.

Expected Behavior

icingacli cube hoststatus

list the cli commands for hoststatus

Current Behavior

icingacli cube The 'cube' module does not provide any CLI commands

Possible Solution

Implement some commands for the hoststatus cube.

icingacli cube hoststatus

cube for host status
====================

Available actions:

additional show addtitional dimensions (doesn't work) columns list the columns of the requestet cube dimensions list all available dimensions examples show examples facts list facts for the cube fullqueryNoNull show the sql query with no null values in the cube. info show information list fetch data from request cube, option --dimensions= required listSlices list slices (doesn't work)

Show help on a specific action: icingacli help hoststatus

The "list" command has the following options:

fetch data from request cube, option --dimensions= required
===========================================================================

USAGE

  icingacli cube hoststatus list --dimensions=[dimensions] [options]

OPTIONS

  --format=csv|json|sql

EXCEPTIONS

  MissingParameter is thrown if dimensions is not given

EXAMPLE

  icingacli cube hoststatus list --dimensions=OS

An example output with format=csv is:

icingacli cube hoststatus list --dimensions=os --format=csv

os,hosts_cnt,hosts_nok,hosts_unhandled_nok
"","214","0","0"
"","215","0","0"
"Linux","1","0","0"

The format=sql show simple the underlying query. To access the "fullquery" I had to change in interface Icinga\Module\Cube\DbCube::fullquery from protected to public.

The example with format=sql is:

icingacli cube hoststatus list --dimensions=os --format=sql

SELECT rollup.os, rollup.hosts_cnt, rollup.hosts_nok, rollup.hosts_unhandled_nok FROM (SELECT sub.os, SUM(hosts_cnt) AS hosts_cnt, SUM(hosts_nok) AS hosts_nok, SUM(hosts_unhandled_nok) AS hosts_unhandled_nok FROM (SELECT c_os.varvalue AS os, COUNT(*) AS hosts_cnt, SUM(CASE WHEN hs.current_state = 0 THEN 0 ELSE 1 END) AS hosts_nok, SUM(CASE WHEN hs.current_state != 0 AND hs.problem_has_been_acknowledged = 0 AND hs.scheduled_downtime_depth = 0 THEN 1 ELSE 0 END) AS hosts_unhandled_nok FROM icinga_objects AS o
INNER JOIN icinga_hosts AS h ON o.object_id = h.host_object_id AND o.is_active = 1
LEFT JOIN icinga_hoststatus AS hs ON hs.host_object_id = h.host_object_id
LEFT JOIN icinga_customvariablestatus AS c_os ON c_os.varname = 'os' AND c_os.object_id = o.object_id GROUP BY c_os.varvalue) AS sub GROUP BY (os) WITH ROLLUP) AS rollup ORDER BY (rollup.os IS NOT NULL) ASC, rollup.os ASC, (rollup.hosts_cnt IS NOT NULL) ASC, rollup.hosts_cnt ASC, (rollup.hosts_nok IS NOT NULL) ASC, rollup.hosts_nok ASC, (rollup.hosts_unhandled_nok IS NOT NULL) ASC, rollup.hosts_unhandled_nok ASC

I fork the module and create a branch "feature-cli-command-hoststatus-WIP". This branch will be only for develop. If everything is fine I will create the final branch from which I create the pull request.

Please give some infos, if the feature will be accepted, so that I could continue with implementing the feature. Give the info if I could change the method "fullquery" like described.

kobmaki commented 6 years ago

Still waiting for response if the feature will be accepted.

kobmaki commented 6 years ago

@Thomas-Gelf @lippserd can you add a comment some thoughts about this enhancement.

nilmerg commented 5 years ago

Hi,

sorry for not responding earlier.

I'm not quite sure what the intention of this feature is. How is this supposed to be used?

The main motivation of this module has ever been a quick overview about one's monitoring environment. Quick in the sense that a few clicks in the UI lead to a useful result.

In which way does this feature expand/support this motivation?

kobmaki commented 5 years ago

It is always handy if you have an command line option. I use the command line for quick grouping of information.

We can disguss this on the 10th Anniversary Party.

lippserd commented 4 years ago

Hey,

Sorry that this request did not get the appropriate attention in the past. I think a CLI command does not harm here. It is also handy for scripting.

I'll have a look at the PR and send you the feedback there.

All the best, Eric