Skip to content

Commit

Permalink
Fix Google Workspace Atom feed failed (#12)
Browse files Browse the repository at this point in the history
* Fix Google Workspace Atom feed failed

* Remove Node Options

* Add Summary test
  • Loading branch information
mikhail-vl committed Feb 3, 2022
1 parent 7ba8a92 commit 42a9e15
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.3.1 (2022-02-02)

### Bug fixes

- Google Workspace Atom feed failed #11

## 1.3.0 (2022-01-24)

### Features / Enhancements
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"upgrade": "yarn upgrade --latest",
"watch": "grafana-toolkit plugin:dev --watch"
},
"version": "1.3.0"
"version": "1.3.1"
}
60 changes: 55 additions & 5 deletions provisioning/dashboards/panels.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"id": 2,
"options": {
"content": "<table width=100% style='border:0'>\n<tr>\n<td style='border:0'><h3><a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a></h3>\n{{{content:h4}}}</td>\n<td rowspan=2 style='border:0' width=200px>\n<div style='max-width: 100%; display: inline; height: auto '><img width=200px height=100% src=\"{{content:img-src}}\"></div></td>\n</tr>\n<tr>\n<td style='border:0'><b>{{date pubDate 'MMM, DD YYYY'}} by {{dc:creator}}</b></td>\n</table>",
"defaultContent": "The query didn't return any results."
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
"pluginVersion": "8.3.3",
"targets": [
Expand Down Expand Up @@ -80,7 +81,8 @@
"id": 4,
"options": {
"content": "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style='border:0px !important'>\n<tr style='border:0px'>\n<td style='border:0px'><img height=100 src=\"{{og:image}}\"></td>\n<td style='border:0px'><b>{{date pubDate 'MMM DD'}}</b><h3><a style='color:blue' target=\"_blank\" href=\"{{link}}\">{{title}}</a></h3>{{description}}\n</td>\n</tr>\n</table>",
"defaultContent": "The query didn't return any results."
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
"pluginVersion": "8.3.3",
"targets": [
Expand Down Expand Up @@ -125,7 +127,8 @@
"id": 3,
"options": {
"content": "# {{date pubDate 'LLL'}} <a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a>\n{{description}}\n\n<a href='{{guid}}' style='color:gray'>{{guid}}</a>",
"defaultContent": "The query didn't return any results."
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
"pluginVersion": "8.3.3",
"targets": [
Expand Down Expand Up @@ -170,7 +173,8 @@
"id": 6,
"options": {
"content": "# {{date updated 'LLL'}} <a target=\"_blank\" style=\"color:blue\" href='{{link}}'>{{title}}</a>\n{{{content}}}",
"defaultContent": "The query didn't return any results."
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
"pluginVersion": "8.3.3",
"targets": [
Expand Down Expand Up @@ -200,6 +204,52 @@
}
],
"type": "marcusolsson-dynamictext-panel"
},
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "PE12154EB4CA97411"
},
"gridPos": {
"h": 17,
"w": 13,
"x": 0,
"y": 34
},
"id": 7,
"options": {
"content": "# {{date pubDate 'LLL'}} <a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a>\n{{{summary}}}",
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
"pluginVersion": "8.3.3",
"targets": [
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "PE12154EB4CA97411"
},
"feedType": "items",
"refId": "A"
}
],
"title": "Google Workspace",
"transformations": [
{
"id": "convertFieldType",
"options": {
"conversions": [
{
"dateFormat": "ddd, DD MMM YYYY HH:mm:ss ZZ",
"destinationType": "time",
"targetField": "pubDate"
}
],
"fields": {}
}
}
],
"type": "marcusolsson-dynamictext-panel"
}
],
"refresh": "",
Expand All @@ -217,6 +267,6 @@
"timezone": "",
"title": "Panels",
"uid": "O4tc_E6Gz",
"version": 8,
"version": 2,
"weekStart": ""
}
8 changes: 8 additions & 0 deletions provisioning/datasources/datasource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ datasources:
editable: true
jsonData:
feed: https://status.redis.com/history.atom
- name: Google Workspace
type: volkovlabs-rss-datasource
access: proxy
orgId: 1
version: 1
editable: true
jsonData:
feed: https://www.google.com/appsstatus/dashboard/en/feed.atom
2 changes: 1 addition & 1 deletion src/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Api', () => {

it('Should make getFeed request for Atom', async () => {
xmlResponse.data =
'<?xml version="1.0" encoding="UTF-8"?>\n<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">\n <id>tag:status.redis.com,2005:/history</id>\n <link rel="alternate" type="text/html" href="https://status.redis.com"/>\n <link rel="self" type="application/atom+xml" href="https://status.redis.com/history.atom"/>\n <title>Redis Status - Incident History</title>\n <updated>2021-12-26T15:23:56Z</updated>\n <author>\n <name>Redis</name>\n </author>\n <entry>\n <id>tag:status.redis.com,2005:Incident/8938651</id>\n <published>2021-12-26T14:45:23Z</published>\n <updated>2021-12-26T14:45:23Z</updated>\n <link rel="alternate" type="text/html" href="https://status.redis.com/incidents/q5bb6tbftgrm"/>\n <title>Instance failure</title>\n <content type="html">&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;26&lt;/var&gt;, &lt;var data-var=\'time\'&gt;14:45&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Resolved&lt;/strong&gt; - This incident has been resolved.&lt;/p&gt;&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;26&lt;/var&gt;, &lt;var data-var=\'time\'&gt;14:38&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Investigating&lt;/strong&gt; - We are experiencing instance failure on GCP/us-east1 , this may affect resources that have the following pattern in their endpoint: c16307.us-east1-mz&lt;/p&gt;</content>\n </entry>\n <entry>\n <id>tag:status.redis.com,2005:Incident/8899527</id>\n <published>2021-12-21T01:37:14Z</published>\n <updated>2021-12-21T01:37:14Z</updated>\n <link rel="alternate" type="text/html" href="https://status.redis.com/incidents/1t2rmcmnp7wd"/>\n <title>Scheduled Maintenance</title>\n <content type="html">&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;21&lt;/var&gt;, &lt;var data-var=\'time\'&gt;01:37&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Resolved&lt;/strong&gt; - This incident has been resolved.&lt;/p&gt;&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;21&lt;/var&gt;, &lt;var data-var=\'time\'&gt;01:01&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Monitoring&lt;/strong&gt; - Service maintenance on AWS/us-west-2 applies to all resources with the following pattern in their endpoint : c2638.us-west-2-mz&lt;/p&gt;</content>\n </entry>\n</feed>\n';
'<?xml version="1.0" encoding="UTF-8"?>\n<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">\n <id>tag:status.redis.com,2005:/history</id>\n <link rel="alternate" type="text/html" href="https://status.redis.com"/>\n <link rel="self" type="application/atom+xml" href="https://status.redis.com/history.atom"/>\n <title>Redis Status - Incident History</title>\n <updated>2021-12-26T15:23:56Z</updated>\n <author>\n <name>Redis</name>\n </author>\n <entry>\n <id>tag:status.redis.com,2005:Incident/8938651</id>\n <published>2021-12-26T14:45:23Z</published>\n <updated>2021-12-26T14:45:23Z</updated>\n <link rel="alternate" type="text/html" href="https://status.redis.com/incidents/q5bb6tbftgrm"/>\n <title>Instance failure</title>\n <content type="html">&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;26&lt;/var&gt;, &lt;var data-var=\'time\'&gt;14:45&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Resolved&lt;/strong&gt; - This incident has been resolved.&lt;/p&gt;&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;26&lt;/var&gt;, &lt;var data-var=\'time\'&gt;14:38&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Investigating&lt;/strong&gt; - We are experiencing instance failure on GCP/us-east1 , this may affect resources that have the following pattern in their endpoint: c16307.us-east1-mz&lt;/p&gt;</content><summary type="html">&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;26&lt;/var&gt;, &lt;var data-var=\'time\'&gt;14:45&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Resolved&lt;/strong&gt; - This incident has been resolved.&lt;/p&gt;&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;26&lt;/var&gt;, &lt;var data-var=\'time\'&gt;14:38&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Investigating&lt;/strong&gt; - We are experiencing instance failure on GCP/us-east1 , this may affect resources that have the following pattern in their endpoint: c16307.us-east1-mz&lt;/p&gt;</summary>\n </entry>\n <entry>\n <id>tag:status.redis.com,2005:Incident/8899527</id>\n <published>2021-12-21T01:37:14Z</published>\n <updated>2021-12-21T01:37:14Z</updated>\n <link rel="alternate" type="text/html" href="https://status.redis.com/incidents/1t2rmcmnp7wd"/>\n <title>Scheduled Maintenance</title>\n <content type="html">&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;21&lt;/var&gt;, &lt;var data-var=\'time\'&gt;01:37&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Resolved&lt;/strong&gt; - This incident has been resolved.&lt;/p&gt;&lt;p&gt;&lt;small&gt;Dec &lt;var data-var=\'date\'&gt;21&lt;/var&gt;, &lt;var data-var=\'time\'&gt;01:01&lt;/var&gt; UTC&lt;/small&gt;&lt;br&gt;&lt;strong&gt;Monitoring&lt;/strong&gt; - Service maintenance on AWS/us-west-2 applies to all resources with the following pattern in their endpoint : c2638.us-west-2-mz&lt;/p&gt;</content>\n </entry>\n</feed>\n';

let result = await api.getFeed({ refId: 'A', feedType: FeedTypeValue.ALL });
expect(result?.length).toEqual(2);
Expand Down
16 changes: 14 additions & 2 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { XMLParser } from 'fast-xml-parser';
import { lastValueFrom } from 'rxjs';
import { DataSourceInstanceSettings, FieldType, MutableDataFrame } from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { FeedTypeValue, ItemKeys, MetaProperties } from '../constants';
import { alwaysArray, FeedTypeValue, ItemKeys, MetaProperties } from '../constants';
import { DataSourceOptions, Query } from '../types';
import { setItem } from '../utils';

Expand Down Expand Up @@ -44,7 +44,12 @@ export class Api {
/**
* Parse XML
*/
const parser = new XMLParser({ ignoreAttributes: false });
const parser = new XMLParser({
ignoreAttributes: false,
isArray: (name, jpath, isLeafNode, isAttribute) => {
return alwaysArray.indexOf(jpath) !== -1 ? true : false;
},
});
const data = parser.parse(response.data as any);

/**
Expand Down Expand Up @@ -203,6 +208,13 @@ export class Api {
value = value['#text'];
}

/**
* Parse Summary
*/
if (key === ItemKeys.SUMMARY && value['#text']) {
value = value['#text'];
}

setItem(entries, key, value);
});
});
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export enum MetaProperties {
export enum ItemKeys {
LINK = 'link',
CONTENT = 'content',
SUMMARY = 'summary',
META = 'meta',
GUID = 'guid',
CONTENT_ENCODED = 'content:encoded',
Expand All @@ -61,3 +62,8 @@ export enum ItemKeys {
CONTENT_IMG_SRC = 'content:img-src',
PUB_DATE = 'pubDate',
}

/**
* Parse as Array
*/
export const alwaysArray = ['feed.entry'];

0 comments on commit 42a9e15

Please sign in to comment.