Skip to content

Commit

Permalink
add dashboard var get/set
Browse files Browse the repository at this point in the history
  • Loading branch information
jgstew committed Apr 1, 2024
1 parent edc0e29 commit ee1234e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/besapi/besapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from lxml import etree, objectify
from pkg_resources import resource_filename

__version__ = "3.2.2"
__version__ = "3.2.3"

besapi_logger = logging.getLogger("besapi")

Expand Down Expand Up @@ -393,6 +393,34 @@ def logout(self):
self.session.cookies.clear()
self.session.close()

def set_dashboard_variable_value(
self, dashboard_name, var_name, var_value, private=False
):
"""set the variable value from a dashboard datastore"""

dash_var_xml = f"""<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
<DashboardData>
<Dashboard>{dashboard_name}</Dashboard>
<Name>{var_name}</Name>
<IsPrivate>{str(private).lower()}</IsPrivate>
<Value>{var_value}</Value>
</DashboardData>
</BESAPI>
"""

return self.post(
f"dashboardvariable/{dashboard_name}/{var_name}", data=dash_var_xml
)

def get_dashboard_variable_value(self, dashboard_name, var_name):
"""get the variable value from a dashboard datastore"""

return str(
self.get(
f"dashboardvariable/{dashboard_name}/{var_name}"
).besobj.DashboardData.Value
)

def validate_site_path(self, site_path, check_site_exists=True, raise_error=False):
"""make sure site_path is valid"""

Expand Down
15 changes: 15 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import argparse
import os
import random
import subprocess
import sys

Expand Down Expand Up @@ -128,6 +129,20 @@ class RequestResult(object):
assert "test_besapi_upload.txt</URL>" in str(upload_result)
print(bigfix_cli.bes_conn.parse_upload_result_to_prefetch(upload_result))

dashboard_name = "_PyBESAPI_tests.py"
var_name = "TestVarName"
var_value = "TestVarValue " + str(random.randint(0, 9999))

print(
bigfix_cli.bes_conn.set_dashboard_variable_value(
dashboard_name, var_name, var_value
)
)

assert var_value in str(
bigfix_cli.bes_conn.get_dashboard_variable_value(dashboard_name, var_name)
)

if os.name == "nt":
subprocess.run(
'CMD /C python -m besapi ls clear ls conf "query number of bes computers" version error_count exit',
Expand Down

0 comments on commit ee1234e

Please sign in to comment.