Package: libprobe
Python library for building InfraSonar ProbesThis library is created for buildingInfraSonarprobes.Environment variableVariableDefaultDescriptionAGENTCORE_HOST127.0.0.1Hostname or Ip address of the AgentCore.AGENTCORE_PORT8750AgentCore port to connect to.ENCRYPTION_KEYdefaultUse your own encryption key for encrypting secrets in the YAML file.INFRASONAR_CONF/data/config/infrasonar.yamlFile with probe and asset configuration like credentials.MAX_PACKAGE_SIZE500Maximum package size in kilobytes(1..2000).MAX_CHECK_TIMEOUT300Check time-out is 80% of the interval time withMAX_CHECK_TIMEOUTin seconds as absolute maximum.DRY_RUNnoneDo not run demonized, just return checks and assets specified in the given yaml(see theDry run sectionbelow).LOG_LEVELwarningLog level (debug,info,warning,errororcritical).LOG_COLORIZED0Log using colors (0=disabled,1=enabled).LOG_FTM%y%m%d %H:%M:%SLog format prefix.OUTPUT_TYPEJSONSet the output type toJSONorPPRINT(Only for a dry run).UsageBuilding an InfraSonar.get_stateimportloggingfromlibprobe.assetimportAssetfromlibprobe.probeimportProbefromlibprobe.severityimportSeverityfromlibprobe.exceptionsimport(CheckException,IgnoreResultException,IgnoreCheckException,IncompleteResultException,NoCountException,)__version__="0.1.0"asyncdefmy_first_check(asset:Asset,asset_config:dict,check_config:dict):"""My first check.Arguments:asset:        Asset contains an id, name and check which should be usedfor logging;asset_config: local configuration for this asset, for example credentials;check_config: configuration for this check; contains for example theinterval at which the check is running and an address ofthe asset to probe;"""if"ignore_this_check_iteration":# nothing will be send to InfraSonar for this check iteration;raiseIgnoreResultException()if"no_longer_try_this_check":# nothing will be send to InfraSonar for this check iteration and the# check will not start again until the probe restarts or configuration# has been changed;raiseIgnoreCheckException()if"something_has_happened":# send a check error to InfraSonar because something has happened which# prevents us from building a check result; The default severity for a# CheckException is MEDIUM but this can be overwritten;raiseCheckException("something went wrong",severity=Severity.LOW)if"something_unexpected_has_happened":# other exceptions will be converted to CheckException, MEDIUM severityraiseException("something went wrong")# A check result may have multiple types, items, and/or metricsresult={"myType":[{"name":"my item"}]}if"result_is_incomplete":# optionally, IncompleteResultException can be given another severity;# the default severity is LOW.raiseIncompleteResultException('missing type x',result)if"not_count_as_check_result":# optionally, NoCountException can be raised in which case the check# result is not counted by InfraSonar; Thus, the last seen services# will not "see" this check result.# A severity can be given if we also want a check error; (similar to# the IncompleteResultException exception)raiseNoCountException('do not count this check result',result)# Use the asset in logging; this will include asset info and the check keylogging.info(f"log something;{asset}")# Return the check resultreturnresultif__name__=="__main__":checks={"myFirstCheck":my_first_check,}# Initialize the probe with a name, version and checksprobe=Probe("myProbe",__version__,checks)# Start the probeprobe.start()ASCII item namesInfraSonar requires each item to have a uniquenameproperty. The value fornamemust be astringwith ASCII compatible character.
When yournameis not guaranteed to be ASCII compatible, the following code replaces the incompatible characters with question marks (?):name=name.encode('ascii',errors='replace').decode()ConfigWhen using apasswordorsecretwithin aconfigsection, the library
will encrypt the value so it will be unreadable by users. This must not be
regarded as true encryption as the encryption key is publicly available.Example yaml configuration:exampleProbe:config:username:alicepassword:secret_passwordassets:-id:123config:username:bobpassword:"mysecret"-id:[456,789]config:username:charliepassword:"myothersecret"otherProbe:use:exampleProbe# use the exampleProbe config for this probeDry runCreate a yaml file, for example(test.yaml):asset:name:"foo.local"check:"system"config:address:"192.168.1.2"Run the probe with theDRY_RUNenvironment variable set the the yaml file above.DRY_RUN=test.yaml python main.pyNote: Optionally an assetidmight be given which can by used to find asset configuration in the local asset configuration file. Assetconfigis also optional.Dump to JSONA dry run writes all log tostderrand only the JSON dump is written tostdout. Therefore, writing the output to JSON is easy:DRY_RUN=test.yaml python main.py > dump.json