Esempio n. 1
0
 def load(self):
     """load a config file from disk"""
     try:
         with open(self.config_file,'r') as f:
             self.update(yaml_load(f.read()))
     except FileNotFoundError:
         pass
Esempio n. 2
0
def discovery_report():
    _data = request.form.get('data')
    _error = request.form.get('error')
    if _data is not None:
        try:
            data = helper.yaml_load(_data)
        except:
            print(_data)
            raise
        # store data
        host_info = HostInfo.query.filter_by(mac=data['mac'].lower()).first()
        if host_info is None:
            app.logger.info('New Discovered Host: {}'.format(data['mac']))
            # create host_info
            host_info = models.HostInfo(mac=data['mac'].lower(),
                                        first_seen=datetime.utcnow())
        else:
            app.logger.info('Updated Discovered Host: {}'.format(data['mac']))
        # update host data
        host_info.last_seen = datetime.utcnow()
        host_info.serialnumber = data['serialnumber']
        host_info.cpu_model = data['cpu_model']
        host_info.ram_bytes = data['ram_bytes']
        host_info.interface = data['interface']
        host_info.discovery_yaml = _data
        host_info.remove_state('rediscover')
        host_info.add_state('discovered')
        # store in database
        db.session.add(host_info)
        db.session.commit()
        host_info = models.HostInfo.query.filter_by(
            mac=data['mac'].lower()).first()
        return str(host_info.mac)
    if _error is not None:
        app.logger.warning('Discovery Error: {}'.format(_error))
        # TODO add to database
        pass
    return ''
Esempio n. 3
0
def query_server_yaml(u):
    y = query_server(u)
    return yaml_load(y)