test_script.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python
  2. '''
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. '''
  17. def get_tokens():
  18. '''
  19. return a tuple of tokens in the format {{site/property}} that will be used
  20. to build the dictionary passed into execute
  21. '''
  22. return ('{{foo-site/bar}}','{{foo-site/baz}}')
  23. def execute(configurations={}, parameters={}, host_name=None):
  24. '''
  25. returns a tuple containing the result code and a pre-formatted result label
  26. '''
  27. # short circuit the script when a parameter is present
  28. if "script.parameter.foo" in parameters:
  29. return "OK", ["Script parameter detected: " + parameters["script.parameter.foo"]]
  30. if configurations is not None:
  31. if '{{foo-site/bar}}' in configurations:
  32. bar = configurations['{{foo-site/bar}}']
  33. if '{{foo-site/baz}}' in configurations:
  34. baz = configurations['{{foo-site/baz}}']
  35. if '{{foo-site/skip}}' in configurations:
  36. return ('SKIPPED', ['This alert is skipped and will not be in the collector'])
  37. label = "bar is {0}, baz is {1}".format(bar, baz)
  38. return ('WARNING', [label])