<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _check_status(sdp_state):
 """SDP Status check. Do all the tests to determine, if the SDP state is "broken", what could be the cause, and return a suitable status message to be sent back by the calling function. """

    try:
        errval = "error"
        errdict = dict(state="unknown", reason="unknown")
        if sdp_state.current_state == "unknown":
            errdict['reason'] = 'database not initialised.'
            LOG.debug('Current state is unknown;')
            LOG.debug('Target state is %s;', sdp_state.target_state)
            LOG.debug('Current state timestamp is %s;',
                      sdp_state.current_timestamp)
        elif sdp_state.current_state is None:
            errdict['reason'] = 'Master Controller Services may have died.'
            LOG.debug('Current state is NONE;')
            LOG.debug('Target state is %s;', sdp_state.target_state)
            LOG.debug('Current state timestamp is %s;',
                      sdp_state.current_timestamp)
        elif sdp_state.target_state is None:
            errdict['reason'] = 'Master Controller Services may have died.'
            LOG.debug('Current state is  %s;',
                      sdp_state.current_state)
            LOG.debug('Target state is NONE;')
            LOG.debug('Current state timestamp is %s;',
                      sdp_state.current_timestamp)
            LOG.debug('Target state timestamp is %s;',
                      sdp_state.target_timestamp)
        elif sdp_state.current_timestamp is None:
            errdict['reason'] = 'Master Controller Services may have died.'
            LOG.debug('Current state is  %s;',
                      sdp_state.current_state)
            LOG.debug('Target state is %s;', sdp_state.target_state)
            LOG.debug('Current state timestamp is NONE')
            LOG.debug('Target state timestamp is %s;',
                      sdp_state.target_timestamp)
        elif sdp_state.target_timestamp is None:
            errdict['reason'] = 'Master Controller Services may have died.'
            LOG.debug('Current state is  %s;',
                      sdp_state.current_state)
            LOG.debug('Target state is %s;', sdp_state.target_state)
            LOG.debug('Current state timestamp is %s;',
                      sdp_state.current_timestamp)
            LOG.debug('Target state timestamp is NONE')
        elif sdp_state.current_timestamp < sdp_state.target_timestamp:
            errdict['reason'] = \
                'Timestamp for Master Controller Services is stale.'
            LOG.debug('Current state is  %s;',
                      sdp_state.current_state)
            LOG.debug('Target state is %s;', sdp_state.target_state)
            LOG.debug('Current state timestamp is %s;',
                      sdp_state.current_timestamp)
            LOG.debug('Target state timestamp is %s;',
                      sdp_state.target_timestamp)
        else:
            errval = "okay"
    except ConnectionError as err:
        errdict['reason'] = err
        LOG.debug('Connection Error %s', err)
    return errval, errdict