#NEWLINE# def present( name , type , url , access = 'proxy' , user = '' , password = '' , database = '' , basic_auth = False , basic_auth_user = '' , basic_auth_password = '' , is_default = False , json_data = None , profile = 'grafana' ) : #NEWLINE# #INDENT# "\n    Ensure that a data source is present.\n\n    name\n        Name of the data source.\n\n    type\n        Which type of data source it is ('graphite', 'influxdb' etc.).\n\n    url\n        The URL to the data source API.\n\n    user\n        Optional - user to authenticate with the data source\n\n    password\n        Optional - password to authenticate with the data source\n\n    basic_auth\n        Optional - set to True to use HTTP basic auth to authenticate with the\n        data source.\n\n    basic_auth_user\n        Optional - HTTP basic auth username.\n\n    basic_auth_password\n        Optional - HTTP basic auth password.\n\n    is_default\n        Default: False\n    " #NEWLINE# if isinstance ( profile , string_types ) : #NEWLINE# #INDENT# profile = __salt__ [ 'config.option' ] ( profile ) #NEWLINE# #UNINDENT# ret = { #NEWLINE# #INDENT# 'result' : None , #NEWLINE# 'comment' : None , #NEWLINE# 'changes' : None , #NEWLINE# #UNINDENT# } #NEWLINE# datasource = _get_datasource ( profile , name ) #NEWLINE# data = _get_json_data ( name , type , url , access , user , password , name , basic_auth , basic_auth_user , basic_auth_password , is_default , json_data ) #NEWLINE# if datasource : #NEWLINE# #INDENT# requests . put ( _get_url ( profile , datasource [ 'id' ] ) , data , headers = _get_headers ( profile ) , timeout = profile . get ( 'grafana_timeout' , 3 ) ) #NEWLINE# ret [ 'result' ] = True #NEWLINE# ret [ 'changes' ] = _diff ( datasource , data ) #NEWLINE# if ( ret [ 'changes' ] [ 'new' ] or ret [ 'changes' ] [ 'old' ] ) : #NEWLINE# #INDENT# ret [ 'comment' ] = 'Data source {0} updated' . format ( name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'changes' ] = None #NEWLINE# ret [ 'comment' ] = 'Data source {0} already up-to-date' . format ( name ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# requests . post ( '{0}/api/datasources' . format ( profile [ 'grafana_url' ] ) , data , headers = _get_headers ( profile ) , timeout = profile . get ( 'grafana_timeout' , 3 ) ) #NEWLINE# ret [ 'result' ] = True #NEWLINE# ret [ 'comment' ] = 'New data source {0} added' . format ( name ) #NEWLINE# ret [ 'changes' ] = data #NEWLINE# #UNINDENT# return ret