A TypeScript library that uses Ollama to parse SSH output into structured data using Zod schemas.
- Parse raw SSH output into structured JSON objects
- Type-safe parsing with Zod schemas
- Local LLM processing using Ollama
- Node.js (>= 18.17.0)
- npm
- Ollama installed and running locally
npm install ssh-llamaFirst, 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']
// }Parses raw SSH output into a structured object based on a given Zod schema.
schema: A Zod schema that defines the structure of the outputmodel: The Ollama model to use (e.g., "llama2")rawSSHString: The raw SSH output to parse
- A promise that resolves to either the parsed object matching the schema or
nullif parsing fails
npm run build# Run tests once
npm test
# Run tests in watch mode
npm run test:watchnpm run exampleThe library has been tested with various network device outputs:
- Linux servers
- Cisco IOS switches
- FortiGate firewalls
- Aruba switches
ISC
- 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
