Skip to content

Commit 9cde34a

Browse files
authored
Add support for news panel (#419)
* Add support for news panel * Fix linting
1 parent d9793a8 commit 9cde34a

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ x.x.x (TBD)
1212
* Added StateTimeline panel which was added in Grafana v8
1313
* Added support for timeseries panel added in Grafana v8
1414
* Added MinMetricAgg and PercentilesMetricAgg to Elasticsearch
15+
* Added support for News panel
1516
* Added support for Pie Chart v2 from Grafana v8
1617

1718
Changes

grafanalib/core.py

+27
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def to_json_data(self):
9595
PIE_CHART_V2_TYPE = 'piechart'
9696
TIMESERIES_TYPE = 'timeseries'
9797
WORLD_MAP_TYPE = 'grafana-worldmap-panel'
98+
NEWS_TYPE = 'news'
9899

99100
DEFAULT_FILL = 1
100101
DEFAULT_REFRESH = '10s'
@@ -3397,3 +3398,29 @@ def to_json_data(self):
33973398
'type': STATE_TIMELINE_TYPE,
33983399
}
33993400
)
3401+
3402+
3403+
@attr.s
3404+
class News(Panel):
3405+
"""Generates News panel json structure
3406+
Grafana docs on State Timeline panel: https://grafana.com/docs/grafana/next/visualizations/news-panel/
3407+
3408+
:param feedUrl: URL to query, only RSS feed formats are supported (not Atom).
3409+
:param showImage: Controls if the news item social (og:image) image is shown above text content
3410+
:param useProxy: If the feed is unable to connect, consider a CORS proxy
3411+
"""
3412+
feedUrl = attr.ib(default='', validator=instance_of(str))
3413+
showImage = attr.ib(default=True, validator=instance_of(bool))
3414+
useProxy = attr.ib(default=False, validator=instance_of(bool))
3415+
3416+
def to_json_data(self):
3417+
return self.panel_json(
3418+
{
3419+
'options': {
3420+
'feedUrl': self.feedUrl,
3421+
'showImage': self.showImage,
3422+
'useProxy': self.useProxy
3423+
},
3424+
'type': NEWS_TYPE,
3425+
}
3426+
)

grafanalib/tests/test_core.py

+9
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ def test_timeseries():
504504
assert data['title'] == title
505505

506506

507+
def test_news():
508+
title = 'dummy title'
509+
feedUrl = "www.example.com"
510+
news = G.News(title=title, feedUrl=feedUrl)
511+
data = news.to_json_data()
512+
assert data['options']['feedUrl'] == feedUrl
513+
assert data['title'] == title
514+
515+
507516
def test_pieChartv2():
508517
data_source = 'dummy data source'
509518
targets = ['dummy_prom_query']

0 commit comments

Comments
 (0)