|
64 | 64 | import socket |
65 | 65 | from datetime import datetime, timedelta |
66 | 66 | from time import sleep |
| 67 | +from typing import Any |
67 | 68 | from urllib import parse |
68 | 69 |
|
69 | 70 | try: |
@@ -102,6 +103,7 @@ def deprecated(message): # pyright: ignore[reportUnknownParameterType] |
102 | 103 | PATH_APPS = "apps/local/" |
103 | 104 | PATH_CAPABILITIES = "authorization/capabilities/" |
104 | 105 | PATH_CONF = "configs/conf-%s/" |
| 106 | +PATH_DASHBOARDS = "data/ui/views/" |
105 | 107 | PATH_PROPERTIES = "properties/" |
106 | 108 | PATH_DEPLOYMENT_CLIENTS = "deployment/client/" |
107 | 109 | PATH_DEPLOYMENT_TENANTS = "deployment/tenants/" |
@@ -481,6 +483,15 @@ def capabilities(self): |
481 | 483 | response = self.get(PATH_CAPABILITIES) |
482 | 484 | return _load_atom(response, MATCH_ENTRY_CONTENT).capabilities |
483 | 485 |
|
| 486 | + @property |
| 487 | + def dashboards(self): |
| 488 | + """Returns the collection of dashboards for this Splunk instance. |
| 489 | +
|
| 490 | + :return: A :class:`Dashboards` collection of :class:`Dashboard` |
| 491 | + entities. |
| 492 | + """ |
| 493 | + return Dashboards(self) |
| 494 | + |
484 | 495 | @property |
485 | 496 | def event_types(self): |
486 | 497 | """Returns the collection of event types defined in this Splunk instance. |
@@ -3653,6 +3664,42 @@ def create(self, name, definition, **kwargs): |
3653 | 3664 | return Collection.create(self, name, definition=definition, **kwargs) |
3654 | 3665 |
|
3655 | 3666 |
|
| 3667 | +class Dashboard(Entity): |
| 3668 | + """This class represents a dashboard (view) in Splunk.""" |
| 3669 | + |
| 3670 | + def __init__(self, service: "Service", path: str, **kwargs: Any) -> None: |
| 3671 | + Entity.__init__(self, service, path, **kwargs) |
| 3672 | + |
| 3673 | + def export(self) -> str: |
| 3674 | + """Returns the dashboard XML content. |
| 3675 | +
|
| 3676 | + :return: The dashboard XML definition. |
| 3677 | + :rtype: ``string`` |
| 3678 | + """ |
| 3679 | + return self.content.get("eai:data", "") # pyright: ignore[reportUnknownVariableType] |
| 3680 | + |
| 3681 | + |
| 3682 | +class Dashboards(Collection): |
| 3683 | + """This class represents a collection of dashboards. Retrieve this |
| 3684 | + collection using :meth:`Service.dashboards`.""" |
| 3685 | + |
| 3686 | + def __init__(self, service: "Service") -> None: |
| 3687 | + Collection.__init__(self, service, PATH_DASHBOARDS, item=Dashboard) |
| 3688 | + |
| 3689 | + def create(self, name: str, xml: str, **kwargs: Any) -> Entity: # pyright: ignore[reportIncompatibleMethodOverride,reportImplicitOverride] |
| 3690 | + """Creates a dashboard. |
| 3691 | +
|
| 3692 | + :param name: The name for the dashboard. |
| 3693 | + :type name: ``string`` |
| 3694 | + :param xml: The dashboard XML definition. |
| 3695 | + :type xml: ``string`` |
| 3696 | + :param kwargs: Additional arguments (optional). |
| 3697 | + :type kwargs: ``dict`` |
| 3698 | + :return: The :class:`Dashboard` entity. |
| 3699 | + """ |
| 3700 | + return Collection.create(self, name, **{"eai:data": xml, **kwargs}) # pyright: ignore[reportUnknownVariableType] |
| 3701 | + |
| 3702 | + |
3656 | 3703 | class Settings(Entity): |
3657 | 3704 | """This class represents configuration settings for a Splunk service. |
3658 | 3705 | Retrieve this collection using :meth:`Service.settings`.""" |
|
0 commit comments