Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/322220

Change subject: WIP Add grafana_json_datasource
......................................................................

WIP Add grafana_json_datasource

Bug: T147328
Change-Id: I42be8d7f6ee5a6873541fcf00ee6f3af98920981
---
A modules/grafana_json_datasource/files/annotations.php
A modules/grafana_json_datasource/files/index.php
A modules/grafana_json_datasource/files/query.php
A modules/grafana_json_datasource/files/search.php
A modules/grafana_json_datasource/manifests/init.pp
A modules/role/manifests/grafana_json_datasource.pp
6 files changed, 156 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/20/322220/1

diff --git a/modules/grafana_json_datasource/files/annotations.php 
b/modules/grafana_json_datasource/files/annotations.php
new file mode 100644
index 0000000..394ae33
--- /dev/null
+++ b/modules/grafana_json_datasource/files/annotations.php
@@ -0,0 +1,82 @@
+<?php
+
+/**
+ * @author Addshore
+ * @license GPLv2+
+ *
+ * Simple endpoint conforming to spec laid out at
+ * https://github.com/grafana/simple-json-datasource
+ *
+ * @TODO
+ *  - Only provide annotations for the given range?
+ */
+
+if ( $_SERVER['REQUEST_METHOD'] === 'OPTIONS' ) {
+       header('Access-Control-Allow-Headers:accept, content-type');
+       header('Access-Control-Allow-Methods:POST');
+       header('Access-Control-Allow-Origin:*');
+       return;
+}
+
+
+if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
+       $requestBody = file_get_contents('php://input');
+       $request = json_decode( $requestBody, true );
+
+       if ( $request === null ) {
+               die( 'Bad request JSON.' );
+       }
+
+       $query = trim( strtok( $request['annotation']['query'], ' ' ), '#' );
+
+       if ( strpos( $query, 'metawiki:' ) !== 0 ) {
+               die( 'Couldn\'t find metawiki: prefix.' );
+       }
+       $pageTitle = substr( $query, 9 );
+
+       $pageUrl = 'https://meta.wikimedia.org/wiki/' . $pageTitle . 
'?action=raw';
+       $pageBody = file_get_contents( $pageUrl );
+
+       if( $pageBody === false ) {
+               die( 'Request to ' . $pageUrl . ' failed.' );
+       }
+
+       $data = json_decode( $pageBody, true );
+
+       if ( $data === null ) {
+               die( 'Bad page JSON.' );
+       }
+
+       $response = array();
+
+       foreach( $data as $annotationData ) {
+
+               if ( $annotationData['start'] == $annotationData['end'] ) {
+                       $response[] = array(
+                               'annotation' => $request['annotation'],
+                               'title' => 'Event',
+                               'time' => strval( strtotime( 
$annotationData['start'] ) ) . '000',
+                               'text' => $annotationData['note'],
+                       );
+               } else {
+                       $response[] = array(
+                               'annotation' => $request['annotation'],
+                               'title' => 'Start Event',
+                               'time' => strval( strtotime( 
$annotationData['start'] ) ) . '000',
+                               'text' => 'Start: ' . $annotationData['note'],
+                       );
+                       $response[] = array(
+                               'annotation' => $request['annotation'],
+                               'title' => 'End Event',
+                               'time' => strval( strtotime( 
$annotationData['end'] ) ) . '000',
+                               'text' => 'End: ' . $annotationData['note'],
+                       );
+               }
+       }
+
+       header( 'Access-Control-Allow-Origin: *' );
+       echo json_encode( $response );
+       return;
+}
+
+die( 'Request must be POST or OPTIONS.' );
diff --git a/modules/grafana_json_datasource/files/index.php 
b/modules/grafana_json_datasource/files/index.php
new file mode 100644
index 0000000..5142b3f
--- /dev/null
+++ b/modules/grafana_json_datasource/files/index.php
@@ -0,0 +1,5 @@
+<?php
+
+header('Access-Control-Allow-Origin : *');
+
+//This entry point just have to return 200 OK!
diff --git a/modules/grafana_json_datasource/files/query.php 
b/modules/grafana_json_datasource/files/query.php
new file mode 100644
index 0000000..ba6d4c8
--- /dev/null
+++ b/modules/grafana_json_datasource/files/query.php
@@ -0,0 +1,5 @@
+<?php
+
+header('Access-Control-Allow-Origin : *');
+
+die( 'Not yet implemented' );
diff --git a/modules/grafana_json_datasource/files/search.php 
b/modules/grafana_json_datasource/files/search.php
new file mode 100644
index 0000000..ba6d4c8
--- /dev/null
+++ b/modules/grafana_json_datasource/files/search.php
@@ -0,0 +1,5 @@
+<?php
+
+header('Access-Control-Allow-Origin : *');
+
+die( 'Not yet implemented' );
diff --git a/modules/grafana_json_datasource/manifests/init.pp 
b/modules/grafana_json_datasource/manifests/init.pp
new file mode 100644
index 0000000..770f9e9
--- /dev/null
+++ b/modules/grafana_json_datasource/manifests/init.pp
@@ -0,0 +1,38 @@
+# == Class: grafana_json_datasource
+#
+# Grafana is an open-source, feature-rich dashboard and graph editor
+# for Graphite and InfluxDB. See <http://grafana.org/> for details.
+#
+# This Grafana JSON datasource is a collection of simple scripts forming
+# a web api endpoint conforming to the spec laid out in by:
+# https://github.com/grafana/simple-json-datasource
+#
+class grafana_json_datasource(
+    $site_name,
+    $docroot
+) {
+
+    apache::site { $site_name:
+        content => 
template("grafana_json_datasource/apache/grafana-json-datasource.wikimedia.org.erb");
+    }
+
+    file { '/srv/grafana_json_datasource':
+        ensure => 'directory',
+        owner  => 'www-data',
+        group  => 'www-data',
+    }
+
+    $files = [
+        "index.php",
+        "annotations.php",
+        "query.php",
+        "search.php",
+    ]
+
+    file { "/srv/grafana_json_datasource/$files":
+        ensure  => present,
+        owner   => 'root',
+        group   => 'root',
+        source  => "puppet:///modules/grafana_json_datasource/$files",
+    }
+}
diff --git a/modules/role/manifests/grafana_json_datasource.pp 
b/modules/role/manifests/grafana_json_datasource.pp
new file mode 100644
index 0000000..9acff02
--- /dev/null
+++ b/modules/role/manifests/grafana_json_datasource.pp
@@ -0,0 +1,21 @@
+# manifests/role/grafana_json_datasource.pp
+# grafana_json_datasource: Simple JSON datasource for Grafana
+
+class role::grafana_json_datasource {
+
+    system::role { 'role::grafana_json_datasource': description => 'Grafana 
JSON datasource' }
+
+    sslcert::certificate { 'grafana-json-datasource.wikimedia.org': }
+    $ssl_settings = ssl_ciphersuite('apache', 'mid', true)
+
+    monitoring::service { 'https-grafana_json_datasource':
+        description   => 'HTTPS-grafana_json_datasource',
+        check_command => 
'check_ssl_http!grafana-json-datasource.wikimedia.org',
+    }
+
+    class { '::grafana_json_datasource':
+        site_name    => 'grafana-json-datasource.wikimedia.org',
+        docroot      => '/srv/grafana_json_datasource',
+    }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/322220
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I42be8d7f6ee5a6873541fcf00ee6f3af98920981
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Addshore <addshorew...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to