executable_grafana 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python-selenium
  2. import argparse
  3. from selenium import webdriver
  4. from selenium.webdriver.support.wait import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. from selenium.webdriver.common.by import By
  7. from selenium.webdriver.firefox.options import Options
  8. options = Options()
  9. options.headless = True
  10. driver = webdriver.Firefox(options=options)
  11. driver.set_window_size(1280, 1024)
  12. def print_domain(domain):
  13. if "." in domain:
  14. print(domain)
  15. def main(args):
  16. driver.get(
  17. f"https://grafana.intr/d/ogvzsY3mb/web-performance-panelized?orgId=1&refresh=30s&viewPanel=6&var-server={args.host}"
  18. )
  19. WebDriverWait(driver, 5).until(
  20. EC.presence_of_all_elements_located((By.CSS_SELECTOR, "table"))
  21. )
  22. [
  23. print_domain(x.split(" ")[0])
  24. for x in [x.text for x in driver.find_elements(By.XPATH, "//table")][0].split(
  25. "\n"
  26. )[1:]
  27. ]
  28. driver.quit()
  29. if __name__ == "__main__":
  30. parser = argparse.ArgumentParser(description="Get data from Grafana.")
  31. parser.add_argument(
  32. "--host",
  33. required=True,
  34. help="Hostname.",
  35. )
  36. main(parser.parse_args())