hubblo-org / cabestan

Gather and normalize ICT inventory data from multiple sources, to enable automation of ICT carbon and environmental impacts (LCA-inspired) assessments.
Apache License 2.0
13 stars 2 forks source link

Centreon scanner #10

Open da-ekchajzer opened 2 years ago

da-ekchajzer commented 2 years ago

Problem

I want to use cabestan to gather my assets list from my centreon instance.

Solution

centreon centralize host (device for cabestan) and services (usage data for cabestan).

A host is any device that has an IP address and that one wishes to monitor. For example, a physical server, a virtual machine, a temperature probe, an IP camera, a printer or a storage space.
A service is a check point, or indicator, to be monitored on a host. This can be the CPU usage rate, temperature, motion detection, bandwidth usage rate, disk I/O, and so on.

We could export or list devices and services with cabestan.

Export centreon configuration

via Web platform (manual)

doc : https://docs.centreon.com/docs/21.04/monitoring/web-import-export/

A graphical interface to export centreon configuration as a txt file. This will generate CLAPI commands (for a later importation) and redirect them to the /tmp/clapi-export.txt file. The explotation of the file might not be straitforward.

via CLAPI (command line)

doc : https://docs.centreon.com/docs/api/clapi/#export

centreon -u admin -p 'centreon' -e > /tmp/clapi-export.txt

This will generate CLAPI commands (for a later importation) and redirect them to the /tmp/clapi-export.txt file. The explotation of the file might not be straitforward.

List assets

via API v2

OpenAPI spec : https://raw.githubusercontent.com/centreon/centreon/21.10.x/doc/API/centreon-api-v21.10.yaml

To list all resources (Host + service) :

{{baseUrl}}/monitoring/resources?search=anim ullamco&limit=20&page=4&types=service&types=service&states=resources_problems&states=in_downtime&statuses=WARNING&statuses=UNREACHABLE&hostgroup_names=amet adipisicing proident&hostgroup_names=nisi occaecat Duis&servicegroup_names=aliquip&servicegroup_names=anim&monitoring_server_names=elit nostrud&monitoring_server_names=enim elit &status_types=soft&status_types=soft
result ```json { "result": [ { "type": "service|host", "short_type": "s|h", "id": 12, "name": "Ping", "alias": null, "fqdn": null, "links": { "uris": { "value": "" }, "endpoints": { "value": "" }, "externals": { "value": "" } }, "monitoring_server_name": "Central", "icon": { "id": 12, "name": "memory", "url": "/media/memory.png" }, "parent": { "type": "service|host", "short_type": "s|h", "id": 12, "name": "Central", "alias": "Host", "fqdn": "127.0.0.1", "links": { "uris": { "value": "" }, "endpoints": { "value": "" }, "externals": { "value": "" } }, "status": { "code": { "value": "" }, "name": { "value": "" }, "severity_code": { "value": "" } }, "icon": { "name": { "value": "" }, "url": { "value": "" } } }, "status": { "code": { "value": "" }, "name": { "value": "" }, "severity_code": { "value": "" } }, "in_downtime": false, "acknowledged": false, "severity_level": 1, "duration": "2h 3m", "last_status_change": "1968-09-17T11:25:54.916Z", "last_time_with_no_issue": "1948-09-21T10:42:47.332Z", "tries": "3/3 (H)", "last_check": "1h 45m", "information": "OK - Ping is ok", "active_checks": true, "passive_checks": true }, { "type": "service|host", "short_type": "s|h", "id": 12, "name": "Ping", "alias": null, "fqdn": null, "links": { "uris": { "value": "" }, "endpoints": { "value": "" }, "externals": { "value": "" } }, "monitoring_server_name": "Central", "icon": { "id": 12, "name": "memory", "url": "/media/memory.png" }, "parent": { "type": "service|host", "short_type": "s|h", "id": 12, "name": "Central", "alias": "Host", "fqdn": "127.0.0.1", "links": { "uris": { "value": "" }, "endpoints": { "value": "" }, "externals": { "value": "" } }, "status": { "code": { "value": "" }, "name": { "value": "" }, "severity_code": { "value": "" } }, "icon": { "name": { "value": "" }, "url": { "value": "" } } }, "status": { "code": { "value": "" }, "name": { "value"example output: "" }, "severity_code": { "value": "" } }, "in_downtime": false, "acknowledged": false, "severity_level": 1, "duration": "2h 3m", "last_status_change": "1988-02-06T13:59:45.715Z", "last_time_with_no_issue": "1962-03-02T03:57:21.464Z", "tries": "3/3 (H)", "last_check": "1h 45m", "information": "OK - Ping is ok", "active_checks": true, "passive_checks": true } ], "meta": { "page": 1, "limit": 10, "search": {}, "sort_by": {}, "total": 1 } } ```

Host

To list all host :

{{baseUrl}}/monitoring/hosts?show_service=true&search=anim ullamco&limit=20&page=4

result ```json { "result": [ { "id": { "value": "" }, "alias": { "value": "" }, "display_name": { "value": "" }, "name": { "value": "" }, "state": { "value": "" }, "services": { "value": "" }, "poller_id": 1, "acknowledged": false, "address_ip": "127.0.0.1", "check_attempt": 1, "checked": true, "execution_time": 0.070906, "icon_image": "ppm/operatingsystems-linux-snmp-linux-128.png", "icon_image_alt": "", "last_check": "1977-12-07T09:39:29.803Z", "last_hard_state_change": "1946-08-17T07:02:08.802Z", "last_state_change": "1979-06-02T20:48:41.737Z", "last_time_down": "1998-03-17T14:10:08.840Z", "last_time_unreachable": "2010-06-05T10:24:29.826Z", "last_time_up": "1970-01-18T13:10:58.364Z", "last_update": "1984-12-27T21:31:43.738Z", "max_check_attempts": 3, "output": "OK - 127.0.0.1 rta 0.100ms lost 0%\n", "passive_checks": false, "state_type": 0, "timezone": ":Europe/Paris", "scheduled_downtime_depth": 0, "criticality": 10 }, { "id": { "value": "" }, "alias": { "value": "" }, "display_name": { "value": "" }, "name": { "value": "" }, "state": { "value": "" }, "services": { "value": "" }, "poller_id": 1, "acknowledged": false, "address_ip": "127.0.0.1", "check_attempt": 1, "checked": true, "execution_time": 0.070906, "icon_image": "ppm/operatingsystems-linux-snmp-linux-128.png", "icon_image_alt": "", "last_check": "1950-04-07T07:55:00.342Z", "last_hard_state_change": "1971-07-22T10:48:45.658Z", "last_state_change": "1961-07-27T12:14:07.261Z", "last_time_down": "2007-05-29T09:31:12.846Z", "last_time_unreachable": "1976-05-23T01:01:58.990Z", "last_time_up": "1981-08-04T06:24:38.138Z", "last_update": "1986-09-01T16:47:13.386Z", "max_check_attempts": 3, "output": "OK - 127.0.0.1 rta 0.100ms lost 0%\n", "passive_checks": false, "state_type": 0, "timezone": ":Europe/Paris", "scheduled_downtime_depth": 0, "criticality": 10 } ], "meta": { "page": 1, "limit": 10, "search": {}, "sort_by": {}, "total": 1 } } ```

Service

To list all sevices :

{{baseUrl}}/monitoring/services?search=anim ullamco&limit=20&page=4

result ```json { "result": [ { "id": 5, "description": "Ping", "display_name": "Ping", "state": 0, "check_attempt": "fugiat", "icon_image": "", "icon_image_alt": "", "last_check": "1950-07-23T18:20:41.714Z", "last_state_change": "1975-09-03T15:50:12.031Z", "max_check_attempts": 3, "output": "OK - 127.0.0.1 rta 0.025ms lost 0%\n", "state_type": 1, "criticality": 10, "status": { "code": { "value": "" }, "name": { "value": "" }, "severity_code": { "value": "" } }, "duration": "2h 3m", "hosts": { "id": 12, "alias": "Central", "display_name": "Central", "name": "Central", "state": 0 } }, { "id": 5, "description": "Ping", "display_name": "Ping", "state": 0, "check_attempt": "ut do", "icon_image": "", "icon_image_alt": "", "last_check": "1970-12-21T03:30:32.718Z", "last_state_change": "2013-01-01T04:58:30.751Z", "max_check_attempts": 3, "output": "OK - 127.0.0.1 rta 0.025ms lost 0%\n", "state_type": 1, "criticality": 10, "status": { "code": { "value": "" }, "name": { "value": "" }, "severity_code": { "value": "" } }, "duration": "2h 3m", "hosts": { "id": 12, "alias": "Central", "display_name": "Central", "name": "Central", "state": 0 } } ], "meta": { "page": 1, "limit": 10, "search": {}, "sort_by": {}, "total": 1 } } ```

via CLAPI (command line)

Host

Doc : https://docs.centreon.com/docs/api/clapi/#show-13

Command : centreon -u admin -p 'centreon' -o HOST -a show Output example :

id;name;alias;address;activate
82;sri-dev1;dev1;192.168.2.1;1
83;sri-dev2;dev2;192.168.2.2;1
84;sri-dev3;dev3;192.168.2.3;0
85;sri-dev4;dev4;192.168.2.4;1
86;sri-dev5;dev5;192.168.2.5;1
87;sri-dev6;dev6;192.168.2.6;1
94;sri-dev7;dev7;192.168.2.7;1
95;sri-dev8;dev8;192.168.2.8;1

Service

Doc : https://docs.centreon.com/docs/api/clapi/#show-13

Command : centreon -u admin -p 'centreon' -o SERVICE -a show Output example :

host id;host name;id;description;check command;check command arg;normal check interval;retry check interval;max check attempts;active checks enabled;passive checks enabled;activate
14;Centreon-Server;19;Disk-/;;;;;;2;2;1
14;Centreon-Server;20;Disk-/home;;;;;;2;2;1
14;Centreon-Server;21;Disk-/opt;;;;;;2;2;1
14;Centreon-Server;22;Disk-/usr;;;;;;2;2;1
14;Centreon-Server;23;Disk-/var;;;;;;2;2;1
14;Centreon-Server;151;Load;;;;;;2;2;1
14;Centreon-Server;25;Memory;;;;;;2;2;1
14;Centreon-Server;26;Ping;;;;;;2;2;0
14;Centreon-Server;40;dummy;check_centreon_dummy;!2!critical;;;;2;2;1

IP scanner

Listed IP could be used to feed a network scanner in a second step.

Centron auto-discovery

doc : https://docs.centreon.com/docs/21.04/monitoring/discovery/introduction/

Centreon provide an auto-discovery wizard wich agregates serveral strategies (so have already been explained here) including :

Since the process is only avaible in a graphicall interface it's seems diffuclt to integrate it in cabestan. Thought :

  1. We can document the process for user using the centron scanner
  2. We can be inspired by the existing auto-discovery plugins