Example #1
0
	def _create_log( self, host, log_name, source, filename=None):

		host_key = helpers.inspect_host( host )

		if not helpers.is_valid_log_source( source ):
			raise InvalidLogSourceException

		request = {
			'request': constants.API_NEW_LOG,
			'user_key': self._account_key,
			'host_key': host_key,
			'name': log_name,
			'type': '',
			'retention': constants.DEFAULT_RETENTION,
			'source': source
		}

		request['filename'] = filename if filename is not None else ''

		log_data, success = self._conn.request( request )

		if success:
			if 'log' in log_data and 'key' in log_data['log']:
				host.add_log(log_data['log'] )
				return host, log_data['log']['key']
			else:
				print 'Log information was missing when creating log, log_name=%s, host_name=%s'%(str(log_name),str(host.get_name()))
				return host, None
		else:
			return host, None
Example #2
0
	def remove_host( self, host, **optionals ):
		""" Removes an existing host on Logentries.
			Required Parameters:
				host (host object returned by the create_host method)			
			
			Successful response returns object as follows:
			{
				"response":"ok",
				"host_key":"12345678-1234-1234-1234-123456789123",
				"user_key":"12345678-1234-1234-1234-123456789123",
				"reason": "Host 'host_name' removed."
			}"""

		host_key = helpers.inspect_host( host )

		request = {
			'request': constants.API_RM_HOST,
			'user_key': self._account_key,
			'host_key': host_key
		}

		removed_host, success = self._conn.request( request )

		if success:
			return True
		else:
			return False
Example #3
0
	def remove_log( self, host, log, **optionals ):
		""" Deletes an existing logfile on Logentries.
			Required Parameters:
				host_key (The UUID key of the host containing the log)
				log_key (The UUID key of the log you would like to remove)
			Optional Parameters:
				account_key (Logentries Account Key, can be environment variable or passed to method)

			Successful response returns the following object:
			{
				"response":"ok",
				"host_key":"12345678-1234-1234-1234-123456789123",
				"reason"  :"Log 'log_name' removed",
				"user_key":"12345678-1234-1234-1234-123456789123",
				"log_key" :"12345678-1234-1234-1234-123456789123"
			}"""

		host_key = helpers.inspect_host( host )
		log_key = helpers.inspect_log( log )

		request = {
			'request': constants.API_RM_LOG,
			'user_key': self._account_key,
			'host_key': host_key,
			'log_key': log_key
		}

		removed_log, success = self._conn.request( request )

		if success:
			return True
		else:
			return False
Example #4
0
	def update_host(self, host, **optionals):
		""" Updates an existing host on Logentries.
			Required Parameters:
				host (Host object returned by the create_host method or
					the host_key UUID for it)
			Optional Parameters:
				name	 (The new name you would like to give the host)
				location (The new name of the server you would like to give the host

			Successful response returns object as follows:
			{
				"response":"ok",
				"host": { "logs"    : [],    # List of logs inside host,
												not applicable for creation
						"c"       : 123445678,  #Creation date in Unix Epoch
						"name"    : "name you provided",
						"distver" : "",
						"hostname": "location you provided, else 'nolocation'",
						"object"  : "host",
						"distname": "",
						"key"     : "12345678-1234-1234-1234-123456789123",
						},
				"user_key":"12345678-1234-1234-1234-123456789123"
			}"""

		host_key = helpers.inspect_host(host)

		name = optionals.get('name', '')
		location = optionals.get('location', '')

		if helpers.parameters_are_empty(name, location):
			raise InvalidParametersException(
				"You must provide either 'name' or 'hostname' values to update a host")

		request = {
			'request': constants.API_SET_HOST,
			'user_key': self._account_key,
			'host_key': host_key,
		}

		if name != '':
			request['name'] = name

		if location != '':
			request['hostname'] = location

		host_data, success = self._conn.request(request)