New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

ssh-llama

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssh-llama

Parse SSH output with Zod and Ollama

latest
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

SSH-Llama Logo

SSH-Llama

A TypeScript library that uses Ollama to parse SSH output into structured data using Zod schemas.

Features

  • Parse raw SSH output into structured JSON objects
  • Type-safe parsing with Zod schemas
  • Local LLM processing using Ollama

Prerequisites

  • Node.js (>= 18.17.0)
  • npm
  • Ollama installed and running locally

Installation

npm install ssh-llama

Usage

First, define your Zod schema for the data structure you want to parse:

import { z } from 'zod';
import { parseSSHWithSchema } from './sshTransformer';

const schema = z.object({
  hostname: z.string(),
  uptime: z.number(),
  users: z.array(z.string()),
});

// Example SSH output
const sshOutput = `Linux webserver-prod-01 5.15.0-1054-aws
14:23:02 up 14 days, 6:42, 3 users
USER     TTY      FROM             LOGIN@   IDLE
ubuntu   pts/0    172.31.45.2      14:20    1.00s
jenkins  pts/1    172.31.45.2      10:15    3:12
deploy   pts/2    172.31.45.2      13:45    2.00s`;

// Parse the output
const result = await parseSSHWithSchema(schema, 'llama2', sshOutput);
console.log(result);
// {
//   hostname: 'webserver-prod-01',
//   uptime: 1209600,
//   users: ['ubuntu', 'jenkins', 'deploy']
// }

API Reference

parseSSHWithSchema<T>(schema: ZodSchema<T>, model: string, rawSSHString: string): Promise<T | null>

Parses raw SSH output into a structured object based on a given Zod schema.

Parameters

  • schema: A Zod schema that defines the structure of the output
  • model: The Ollama model to use (e.g., "llama2")
  • rawSSHString: The raw SSH output to parse

Returns

  • A promise that resolves to either the parsed object matching the schema or null if parsing fails

Development

Building

npm run build

Running Tests

# Run tests once
npm test

# Run tests in watch mode
npm run test:watch

Running Example

npm run example

Supported Device Types

The library has been tested with various network device outputs:

  • Linux servers
  • Cisco IOS switches
  • FortiGate firewalls
  • Aruba switches

License

ISC

Contributing

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

Keywords

ssh

FAQs

Package last updated on 22 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts