Edits history of script submission #17269 for ' Send Log Lines (mezmo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Send Log Lines
     * Use this method to send logs to a logging instance.
     */
    export async function main(
    	auth: RT.Mezmo,
    	hostname: string | undefined,
    	body: Body,
    	mac?: string | undefined,
    	ip?: string | undefined,
    	now?: string | undefined,
    	tags?: string | undefined
    ) {
    	const url = new URL(`https://api.mezmo.com/logs/ingest`)
    	for (const [k, v] of [
    		['hostname', hostname],
    		['mac', mac],
    		['ip', ip],
    		['now', now],
    		['tags', tags]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Token ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    
    /* eslint-disable */
    /**
     * This file was automatically generated by json-schema-to-typescript.
     * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
     * and run json-schema-to-typescript to regenerate this file.
     */
    
    export interface Body {
    	lines?: {
    		/**
    		 * UNIX timestamp, including milliseconds, when the log entry was recorded.
    		 */
    		timestamp?: string
    		/**
    		 * Text of the log line.
    		 */
    		line: string
    		/**
    		 * Name of the application that generates the log line.
    		 */
    		app?: string
    		/**
    		 * Set a value for the level. For example, sample values for this parameter are INFO, WARNING, ERROR.
    		 */
    		level?: string
    		/**
    		 * This field is reserved for custom information that is associated with a log line. To add metadata to an API call, specify the meta field under the lines object. Metadata can be viewed inside that line's context.
    		 */
    		meta?: string
    		[k: string]: unknown
    	}[]
    	[k: string]: unknown
    }
    

    Submitted by hugo697 235 days ago