Code Monkey home page Code Monkey logo

glpi_app_grafana's Introduction

GLPI app for Grafana

Introduction

This application gets information in GLPI (Gestion Libre de Parc Informatique). It use the REST API added in version 9.1. You will be able to have graphs, singlestat, tables... of your data (tickets, devices, users...).

screenshot

This is an example:

screenshot1

Datasource

For the GLPI datasource, you will need:

  • the URL of the GLPI API (like http://127.0.0.1/glpi/apirest.php)
  • the App-token, you can generate and get it in GLPI in the menu Setup > General > API
  • the User token, you can generate and get it in the user account/preferences panel in GLPI (named API Token)
  • In the menu Setup > General > API, Enable Rest API and Enable login with external

GLPI Webserver

On your GLPI webserver, you need active the CORS. Documentation about CORS

Apache

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE"
Header set Access-Control-Allow-Credentials true
Header set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, App-Token, Session-Token"

NGINX

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Origin,Content-Type,Accept,Authorization,App-Token,Session-Token';

Dashboard

You can get a simple dashboard here

screenshot1

Table panel

Create a new Table panel and then edit the panel. Select the GLPI datasource and add a new Query in the panel Metrics.

The configuration will require:

  • Query: do a search into GLPI and copy paste the URL here
  • Alias: the alias name of this query, it will appear in the panel
  • Timerange based on: define on which GLPI date field you will get the data. This field is used by the timerange defined in top of grafana
  • Count element: if the panel is a Table, select yes, otherwise keep to no
  • Is it a table?: to display the query result as a Table, check this option else uncheck.

When Is it a table is checked, the query result will be displayed as a table and you can define up to 6 columns to be displayed. For each column in the table, select the query result field and the name of the column.

When Is it a table is not checked, the query result is considered as a usual Grafana timeseries and it will displayed as is. See Grafana table panel for more information.

Single stat panel

Problem with server access

If you have the message: There isn't an active API client matching your IP address in the configuration (ip, ip) where you have 2 IPs and the same, you need apply a patch into GLPI:

diff --git a/inc/api.class.php b/inc/api.class.php
index 3ae2966ce..a4a18dc9e 100644
--- a/inc/api.class.php
+++ b/inc/api.class.php
@@ -105,6 +105,10 @@ abstract class API extends CommonGLPI {

       // retrieve ip of client
       $this->iptxt = Toolbox::getRemoteIpAddress();
+      $spl = explode(',', $this->iptxt);
+      if (count($spl) > 1) {
+         $this->iptxt = $spl[0];
+      }
       $this->ipnum = (strstr($this->iptxt, ':')===false ? ip2long($this->iptxt) : '');

       // check ip access

Bugs / features

If you have a bug repoort or request feature, you can open issues in the github repository

Professional support

Do you need professional support, training, others?

Please contact the DCS Easyware company / send a mail to [email protected]

Changelog

2.0.1

  • compatibility with Grafana 9.x

2.0.0 (unreleased)

  • compatibility with Grafana 8.x
  • rewrite part of code to be easier to read

1.4.0

  • manage variables for GLPI datasource (use the variable name with [[]] like [[myvar]] in the query)
  • add type query in the variable with copy / paste search like for standard queries (it use the name + id of item)

1.3.0

  • add Apache / NGINX configuration in the readme
  • add more instructions in the readme to configure API into GLPI
  • add link of a user dashboard in the readme
  • add the patch of GLPI in the readme when use the datasource in mode server
  • fix PHP timezone in the datasource
  • update dependencies (and so fix some vulnerabilities)
  • fix a bug in number elements displayed in the singlestat panel

1.2.0

  • allow to get a query count without selecting a date field
  • fix #16: no more need to force grunt for rebuilding
  • fix #17: fix error when receiving integer values not formated in strings
  • fix some typos
  • dev: allow to set/unset browser console log

1.1.0

  • compatibility with GLPI 9.2
  • autofill the field Timerange based on in the query
  • when adding a new query, add by default a ticket query instead undefined
  • get correct values in the tooltip when the mouse is hovering the graph
  • enhance error message when defining the datasource
  • add the possibility to have the count of elements by hour of the day with the panel histogram

1.0.0

First version

glpi_app_grafana's People

Contributors

ddurieux avatar mohierf avatar upperm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glpi_app_grafana's Issues

Problem with Cas

Dears,
I have this problem.

I use GLPI with Cas authentication and LDAP authentication, When I remove cas authentication connection work on Grafana., then it's working without Cas, show this message "Data source is working"

On glpi, I discovered this parameter "noCAS=1", if I access glpi doesn't show Cas authentication:

Example:
http://Server-GLPI/glpi/index.php?noCAS=1

I tried add this parameter on my configuration, but doesn't work. Look on picture:

granfa-config

On url option I tried add too:
https://cas.authentication.br/cas/login?service=http://dus.myserver.br/glpi/front/login.php

Show this error with if add this cas authentication:
"Cross-Origin Request Blocked: add right headers in your apache/nginx like 'App-Token' and 'Session-Token"

My config of apache glpi:

apache-config

Can someone help me?

Error with zero values

Good Morning,
I am having problems in queries where the value returned is 0 (No items found).
When I add a query where the result is zero, the chart starts to fail.

Ex.:

image

image

image

Server vs. Browser

Feels a bit that Server and Browser are switched:

When selecting a server as access I've got the following error:
GLPI API Error Response: Es gibt keinen aktiven API-Client, der mit Ihrer IP-Adresse in der Konfiguration übereinstimmt. (Client-IP, Client-IP)
As I'm understanding, when using server no direct request from client to glpi will be made!?
When using Browser:
Cross-Origin Request Blocked: add right headers in your apache/nginx like 'App-Token' and 'Session-Token'

GLPI 9.2.3
Plugin 1.1.0
Grafana 5.1.2

Use several queries in the same panel

Usually, with some Grafana panel, it is allowed to declare several queries in the same panel. As an example, it is possible to declare query A, query B and query C, and only the Query C values are displayed.

It does not look possible in a single stat panel to declare several queries and only display the result of only one of them

Unknown error Cross-Origin Request Blocked: add right headers in your apache/nginx like 'App-Token' and 'Session-Token'

Boa tarde estou com problemas

image

consigo fazer a parte do API no GLPI tudo certo

meu unico problema ta sendo o Apache onde configuro as tag que mostra aqui

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE"
Header set Access-Control-Allow-Credentials true
Header set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, App-Token, Session-Token"

se eu adiciono elas no apache da erro no glpi 404 e nao consigo acessar ai tenho que remover ele para glpi voltar ao normal

GLPI 9.4.3 and app for Grafana 1.3.0

Hi folks,

I have tried to enable cors on a apache without success.
I tried in .htaccess, in glpi.conf or 000-default.conf.

Wich is the correct marker to incapsulate

Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, DELETE" Header set Access-Control-Allow-Credentials true Header set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding, App-Token, Session-Token"

and in wich file?

I got this:

Access to XMLHttpRequest at 'https://glpi###############initSession' (redirected from 'http://#####/api/datasources/proxy/6/initSession') from origin 'http://#######' has been blocked by CORS policy: Request header field x-ds-authorization is not allowed by Access-Control-Allow-Headers in preflight response.

Error Integration with GLPI 9.1.3.

Guys, good morning. First congratulations for the project.

I would like to know if the plugin is GLPI 9.1.3 compliant, I am trying to set up the datasource and am getting the following error:

"Unknown error
GLPI API Error Response: There is no active API client that matches its IP address in the configuration (187.44.177.126, 187.44.177.126) "

The same API is currently in production for other integrations.

Cannot get a sessionToken using basic auth

Problem
Configuring glpi_app_grafan with basic auth does not work.

There is in fact 2 problems:

  1. User Token field is mandatory in the grafana's GLPI datasource configuration GUI. IMHO it is a mistake as the GLPI's API allow other kind of authentications.
  2. The GUI of GLPI datasource configuration allow user to configure basic authentication, but it is ignored.

I found seral places where code calls this.url + "/initSession" and each time it build query with user_token header field.

It should test wich fields it needs and allow use of Autorization: basic with a base64 hash of user: passwd fields as stated in the GLPI's APIREST documentation.

In our environment, using App-Token and User-Token does not work because we authenticate GLPI users with CAS. Maybe it is a bug in GLPI implementation, I don't know.

We use plugin glpi_app_grafana v1.3.0

Thank you

Grafana does not querey

Hi,

I am configuring grafana to query the information about the tickets and it is not able to query them. The datasource connect but there are not results in the dashboard.

I checked Apache logs in GLPI server and we find this message:
192.168.100.23 - - [03/May/2019:12:59:57 +0200] "GET /glpi/apirest.php/search/ticket?is_deleted=0&criteria[0][field]=2&criteria[0][searchtype]=contains&criteria[0][value]=&search=Rechercher&itemtype=Ticket&start=0&criteria[1][link]=AND&criteria[1][field]=0&criteria[1][searchtype]=morethan&_select_criteria[1][value]=0&_criteria[1][value]=1556866797&criteria[1][value]=2019-05-03%2006:59:57&criteria[2][link]=AND&criteria[2][field]=0&criteria[2][searchtype]=lessthan&_select_criteria[2][value]=0&_criteria[2][value]=1556888397&criteria[2][value]=2019-05-03%2012:59:57&forcedisplay[0]=0 HTTP/1.1" 302 - "-" "Grafana/6.1.6"
Also, if we try the query with curl, it has the same message.

Cannot read property 'number' of undefined

Since version 1.2.0 of the plugin, all my GLPI panels returns the same error:

Cannot read property 'number' of undefined

With the full stack trace

TypeError: Cannot read property 'number' of undefined
    at Array.eval (https://graphes.domain.net/public/plugins/ddurieux-glpi-app/datasource/datasource.js:121:60)
    at eval (https://graphes.domain.net/public/plugins/ddurieux-glpi-app/datasource/datasource.js:60:62)
    at u (https://graphes.domain.net/public/build/vendor.337c125610d33424db4a.js:87:68722)
    at https://graphes.domain.net/public/build/vendor.337c125610d33424db4a.js:87:69127
    at h.$digest (https://graphes.domain.net/public/build/vendor.337c125610d33424db4a.js:87:74824)
    at h.$apply (https://graphes.domain.net/public/build/vendor.337c125610d33424db4a.js:87:76638)
    at https://graphes.domain.net/public/build/vendor.337c125610d33424db4a.js:87:72697
    at i (https://graphes.domain.net/public/build/vendor.337c125610d33424db4a.js:87:21870)
    at https://graphes.domain.net/public/build/vendor.337c125610d33424db4a.js:87:23332

Example of query triggering it:
https://tkt.domain.net/front/ticket.php?itemtype=Ticket&sort=2&order=DESC&start=0&criteria[0][field]=12&criteria[0][searchtype]=equals&criteria[0][value]=notold&criteria[1][link]=AND&criteria[1][field]=15&criteria[1][searchtype]=lessthan&criteria[1][value]=NOW&criteria[2][link]=AND&criteria[2][field]=7&criteria[2][searchtype]=notequals&criteria[2][value]=23

Everything was fine with 1.1.0 (and everything is working again as soon as I downgrade back to 1.1.0)

One thing interesting is that, if I edit the applet, and wait a few seconds without changing anything, then the applet starts working. Even if I go back to the dashboard. It works until à reload the page

Running on CentOS 7, Grafana 5.2.0

Problem in query GLPI

Hello dear ddurieux

I am doing the GLPI and Grafana integration, I came across the following problem.

image

or datasourcing is connected

Query responds with error on line 125

Object
xhrStatus:"complete"
request:Object
method:"GET"
url:"api/datasources/proxy/4/search/ticket?is_deleted=0&as_map=0&criteria[0][field]=12&criteria[0][searchtype]=equals&criteria[0][value]=notold&search=Search&itemtype=Ticket&start=0&forcedisplay[0]=0&giveItems=true&forcedisplay[1]=1&forcedisplay[4]=4&forcedisplay[3]=3&forcedisplay[80]=80&forcedisplay[15]=15&forcedisplay[7]=7"
response:"
Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\glpi\inc\api.class.php on line 125
"

follows the line that shows copied error of the patch that was published

  // retrieve ip of client
  $this->iptxt = Toolbox::getRemoteIpAddress();
  •   $spl = explode(',', $this->iptxt);
    
  •     if (count($spl) > l) {    
    
  •    $this->iptxt = $spl[0];
    
  • }
     $this->ipnum = (strstr($this->iptxt, ':')===false ? ip2long($this->iptxt) : '');
    

#line 125 = + if (count($spl) > l) {

help me!!

thanks

Problem with GLPI 9.2.3

Hello there,

I configured the datasource and everything it's saying the datasource is working.

Anyway the dashboard is not working.
I'm using the console view in my browser and i got the following error :

image

image

and i cant find what is the problem.

Thanks for your help

Dynamic split this query by a query per each values of the field

Hello,

With the "Dynamic split this query by a query per each values of the field" options is it possible to make a chart like the image below?

image

I'm doing certain query and counting the value of rows, but I would also like to separate them by group.

Here's how it works in Grafana:

image

With the "Dynamic split this query by a query per each values of the field":

image

API TOKEN NOT FOUND IN GLPI

Hello Ddurieux,

I have a problem, i don't have API token (app token, user token) in my GLPI version 0.90.5.
There is not API in == > Configuration >

I will be very grateful for your help

"datasources" as domain at title link

I just started using this app, so i may forgot to set something, but when i create a table with metrics of tickets i noticed that title come as a <a></a> tag (which made me happy, 'cause i could just set "Sanitize HTML" and the link would work), but then i noticed that the "domain" for some reason was appearing as "datasources" just like below
image

Is it a bug/issue or i just set something wrong?

Table panel columns management

Currently it is possible to use some fields from the request result as columns in the Grafana table panel.

Some remarks:

  • allow more than 6 columns. Perharps 12 columns, same as the panels spanning ...

  • allow to "unselect" a query result field from a column ... currently it is not possilble

  • display the fields of the Glpi metacriteria. For a request joining Computers and Software, the Software fields are not visible

  • using the ID field in a column raises an error :/

  • using the "Nombre de tickets" field in a column raises an error :/

GLPI Datasource - Internal server error.

Hello Ddurieux,

I haven one problem with the integration between GLPI and Grafana:

internal server error

But I'm getting this error when I want to save the DataSource.

Also I just try with Basic Auth, but the same problem still appear.

Do you know what can be the problem?

Thank you.

Regards.

Problem Integration GLPI + Grafana

Hello Mr Ddurieux

How are you? Can you help me?

I Installed the plugin GLPI in Grafana, acoording with instructions in page, but, a message return with error.

Regards

Leandro Tenorio
screenshot_3

no import dashboards

there should be a template glpi_grafana
2017-06-27 18 49 44

image

does not import. Grafana v4.3.2 (commit: ed4d170)

pb with glpi

Hello david.
I have a problem with the configuration of glpi app.
i try to access to my glpi but i have serious problem?
image
My Glpi is configured with SSO authentification, my users are auto authetified with my DC.
so when i try to test my config i have a message to authenticate!
image
but it doesn't accept my login/password for glpi (my windows domain\user and password).

If i try browser access and not server(default) i have a message with cross!
image

image

and my httpd.conf
image

Can you help me?

Jérôme

Server GLPI Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-170-generic x86_64) 192.168.9.11
GLPI 9.4.4
Server Grafana (V6.5.1) CentOS8 192.168.9.14

Error Response

Hello

How are you?

Can you help me?

When I configured the plugin return this error...

image
image

Unable to connect when using proxy connection method on Grafana

t=2017-10-23T10:15:07+0200 lvl=info msg="Request Completed" logger=context userId=35 orgId=5 uname=[email protected] method=GET path=/glpi/apirest.php/initSession status=400 remote_addr="192.168.186.23, 127.0.0.1" time_ms=40 size=142 referer=https://grafana.company.com/datasources/edit/8

In grafana setup dialog, i get this :

GLPI API Error Response: No active client matching your IP address (192.168.186.23, 127.0.0.1, 127.0.0.1)

I tried setting api access without ip restriction or with 127.0.0.1 - 192.168.186.23, even though grafana IP is 172.17.2.29 on my network.

Is this normal to pass two ip's as remote_addr ? Should i somehow rewrite it in apache on glpi side?

I am running Grafana 4.5.2 and GLPI 9.1.6.

Use Query Variable to calculate field

Is there a way to use variables to reference a query to calculate a field.
Here it is what I want to do:

I Have a query returning the total number of problems. Query A
I Have a second query returning the total number of solved problems. Query B

I want to show the percentage of problems solved, using Query B e Query A to calculate it.

Is there a way to do that?

User_Token incorrect

Hi !

I try to configure the DataSource but i alway get this error :

I checked the older issue #26 but it's still not working

My Configuration :

GLPI (9.3)

image

image

API User
image

Grafana (5.2.1)

image

image

My GLPI server is on a VPS (OVH) configured in HTTPS.
I enabled the headers_module in the virtual host and in the apache conf

image
My GLPI is not in HTTP

Thank.
Merci

GLPI 9.1.4

No work, and no imported template grafana.

Differences in results

Hi David! I vave a problem setting up a Singlestat panel so that it shows me the exact same number of items found in glpi. Here's an example:
https://my.glpi.address/glpi/front/computer.php?is_deleted=0&criteria[0][field]=5150&criteria[0][searchtype]=morethan&_select_criteria[0][value]=-4DAY&criteria[0][value]=-4DAY&search=Szukaj&itemtype=Computer&start=0&_glpi_csrf_token=292d836fc52c10bc8d1a418730329b84
This search returns the number 1108. Then I paste the link to a grafana query field, check count elements checkbox, in third tab (Options) I change Stats to Current, which gives me result of 1 item. When I chenge Stats to Total it returns 1090. I couldn't find any explenation on how to use this plugin properly to get the same results as in glpi.
Thanks for Your help.

Panel query elements count is high

When a panel queries for information to Glpi it looks like it is requesting an important number of elements. As of it, on huge tables, the query is very long to update the panel.

It looks like it is getting 400 elements at once ?
image

Because the data source is using a dedicated user account in Glpi, perharps it should only request the maximum page count of the user ?

user not properly displayed in table

Hello,
I'm using a dashboard based on your exemple but some user information are not properly displayed in the table " Last Ticket".
for exemple "Tehnicien" column display:
LE TIEC ERWAN

I don't have issue with the column "demandeur"

I'm using grafana 5.3.2 with glpi plugin 1.3.0
glpi server version is 9.3.2

grafana_glpi

Javascript error -

When some fields contain integer values:

Panel data error: 
TypeError: data[3][idx][kkey][eval(...).number].replace is not a function
Stack trace:
execute/GlpiAppDatasource</GlpiAppDatasource.prototype.promiseMergeTargetResult/<@http://localhost:3000/public/plugins/ddurieux-glpi-app/datasource/datasource.js:255:59
u@http://localhost:3000/public/build/vendor.2305a8e1d478628b1297.js:43:68722
c/<@http://localhost:3000/public/build/vendor.2305a8e1d478628b1297.js:43:69127
$digest@http://localhost:3000/public/build/vendor.2305a8e1d478628b1297.js:43:74824
$apply@http://localhost:3000/public/build/vendor.2305a8e1d478628b1297.js:43:76636
M/a<@http://localhost:3000/public/build/vendor.2305a8e1d478628b1297.js:43:72695
i@http://localhost:3000/public/build/vendor.2305a8e1d478628b1297.js:43:21868
mt/c.defer/n<@http://localhost:3000/public/build/vendor.2305a8e1d478628b1297.js:43:23332
metrics_panel_ctrl.ts:171:6

Getting TotalCount instead of count value as count elements

Hello,

is there a way to get TotalCount value instead of count value in a panel ?

For instance, on the default Dashboard, I would like to retrieve the Total number of Computers.
Count elements is limited by the windowing system (400 by default) used to limit the number of answers returned during a equest.

If you read the query Inspector, it's possible to see totalcount, but I'm not able to retrieve the info in my panel.

Thanks

Installing for development - grunt error

$ grunt
Running "clean:0" (clean) task
>> 1 path cleaned.

Running "copy:src_to_dist" (copy) task
Created 5 directories, copied 14 files

Running "copy:moment_timezone" (copy) task
Copied 8 files

Running "copy:pluginDef" (copy) task
Copied 1 file

Running "babel:dist" (babel) task

Running "ts:build" (ts) task
Compiling...
Using tsc v2.7.1
dist/datasource/query_ctrl.ts(1,21): error TS6053: File '/usr/local/share/grafana/public/app/headers/common.d.ts' not found.
dist/datasource/query_ctrl.ts(3,8): error TS1192: Module '"dist/datasource/datasource"' has no default export.
dist/datasource/datasource.ts(1,21): error TS6053: File '/usr/local/share/grafana/public/app/headers/common.d.ts' not found.

>> 1 syntax error  2 non-emit-preventing type warnings  
>> Error: tsc return code: 2
Warning: Task "ts:build" failed. Use --force to continue.

Aborted due to warnings.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.