Metadata-Version: 2.4
Name: rsi-varlog-explorer
Version: 1.6.3
Summary: Junos RSI and varlog explorer with interactive CLI simulator
Project-URL: Homepage, https://github.hpe.com/ying-wang/rsi-varlog-explorer
Project-URL: Repository, https://github.hpe.com/ying-wang/rsi-varlog-explorer
Project-URL: Issues, https://github.hpe.com/ying-wang/rsi-varlog-explorer/issues
Author: Ying Wang
License: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Networking
Requires-Python: >=3.8
Requires-Dist: httpx
Requires-Dist: prompt-toolkit>=3.0.0
Requires-Dist: pyparsing>=3.1.4
Requires-Dist: pyyaml>=5.4
Provides-Extra: dev
Requires-Dist: mypy>=1.0.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: junos
Requires-Dist: junos-eznc>=2.6.0; extra == 'junos'
Description-Content-Type: text/markdown

# rsi-varlog-explorer

An interactive tool for navigating Junos RSI output and VAR/LOG files through a simulated CLI environment as if you were on the actual device.

- Interactive Junos CLI simulation for RSI and VAR/LOG exploration
- Auto-detects RSI files and var log sources, with automatic archive extraction
- Handles single or dual RE var log inputs
- Operational and configuration mode navigation (`configure`, `edit`, `top`, `up`, `exit`)
- Supports Junos-style `?` query output (for example, `show log messages?`) and keeps the same command text on the next line after showing results
- Supports command completion and shorthand expansion using `Tab` or `Space`
- Accepts partial commands, abbreviations, and minor typos (for example, `show int ter` -> `show interfaces terse`)
- Pipe and output processing: `match`, `grep`, `except`, `find`, `last`, `count`, `trim`, `no-more`, `save`, `display set`
- Pager control (`--no-pager`, `pager on/off`, `Ctrl+C` behavior)
- Optional XML output and XML export/report utilities

## Getting Started (New Users)

### Prerequisites

- SSH access to `p-jtac-lnx02`
- Python 3.8+ on `p-jtac-lnx02` (if not available, pyenv is available — see Optional Setup below)

### Installation

Login to `p-jtac-lnx02` and install (one-time only):

```bash
# Step 1: SSH into the JTAC server
ssh <your_username>@p-jtac-lnx02

# Step 2: Install the tool
pip install rsi-varlog-explorer --user

# Step 3: Add to PATH (make permanent by adding to ~/.bashrc)
export PATH="$HOME/.local/bin:$PATH"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc

# Step 4: Ensure login shells also load ~/.bashrc
# (bash login shells read ~/.bash_profile, NOT ~/.bashrc, by default)
echo '[[ -f ~/.bashrc ]] && . ~/.bashrc' >> ~/.bash_profile

# Step 5: Verify installation
rsi-varlog --version

# Step 6: Grant read/write permission to the file directory if needed
chmod -R u+w /volume/CSdata/<your_username>/case/
```

Done! The tool is now ready to use on lnx02.

---

### Optional Setup (Python < 3.8 only)

If the Python version on `p-jtac-lnx02` is below 3.8, install Python 3.13 via pyenv:

```bash
curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc
pyenv install 3.13 && pyenv global 3.13
python3 --version
# Python 3.13.13
```

### Usage

```bash
# Auto-discover and extract everything into the same directory
# (file directory must be writable and contain RSI & var logs for a single device)
rsi-varlog <file-dir>

# Override individual inputs
--rsi-file <path>        # specify the RSI log file explicitly
--var-log-dir <path>     # specify the var log archive or directory to use

# Redirect extraction to a separate writable directory
# (use this when the case directory is read-only)
--extract-dir <dir>
```

If `--rsi-file` or `--var-log-dir` files reside in the same directory as `<file-dir>`, you can supply bare filenames instead of full paths — the tool will resolve them automatically.

**Example:**
```bash
rsi-varlog /volume/case_2026/2026-0413-672364 --rsi-file 20260413-FFTEQ-BB1-RSI.log --var-log-dir 2026-04-13-FFTEQ-BB1-re0.tgz 2026-04-13-FFTEQ-BB1-re1.tgz --extract-dir /volume/CSdata/annaw/case/2026-0323-648596_test
```

### Interactive Commands

Inside the simulator:

```text
show version
show log ?
show log messages | match <keyword>
show chassis hardware detail no-forwarding
show log messages | last 50
show interfaces terse | match ge-0
quit
```

Press `?` for contextual help, `Ctrl+C` to stop paging, `Ctrl+C` again to exit.

## Publish To PyPI (Maintainers)

1. Bump the version in `pyproject.toml`.
2. Build distributions:

```bash
python3 -m pip install --user -U build twine
python3 -m build
python3 -m twine check dist/*
```

3. Upload to TestPyPI first:

```bash
python3 -m twine upload --repository testpypi dist/*
```

4. Verify install from TestPyPI:

```bash
python3 -m pip install --user -U --index-url https://test.pypi.org/simple/ rsi-varlog-explorer
```

5. Upload to PyPI:

```bash
python3 -m twine upload dist/*
```

## Pipe Commands (`|`)
```text
show interfaces terse | match ge-0
show config | display set | save backup.conf
show interfaces | count
show route | except 0.0.0.0 | last 20
```

Available pipes: `no-more`, `save <file>`, `count`, `match <pattern>`, `except <pattern>`, `last <N>`, `find <pattern>`, `trim <N>`, `display set`

## Limitations
Simulation output is replayed from the RSI. If the RSI does not contain the command you request, you will see `Unknown command` message.

## CLI Options
```text
rsi-varlog <case-directory>                            # interactive mode, full auto-detect
rsi-varlog <case-directory> --no-pager                 # disable paging
rsi-varlog <case-directory> --extract-dir <dir>        # extract archives into <dir> instead of case directory
rsi-varlog <case-directory> --rsi-file <path>          # skip RSI auto-detection, use this file
rsi-varlog <case-directory> --var-log-dir <path>       # use this directory as var log source (one RE)
rsi-varlog <case-directory> --var-log-dir <re0> <re1>  # specify both RE var log directories
```

Full example (case directory read-only, only re0 var logs):
```bash
rsi-varlog /volume/case_2026/2026-0323-648596 \
    --rsi-file  /volume/case_2026/2026-0323-648596/20260323-MTSINARE-PE-01-RSI.log \
    --extract-dir /homes/annaw/rsi-extract/648596 \
    --var-log-dir /homes/annaw/rsi-extract/648596/20260323-MTSINARE-re0/var-re0
```

Full example (both REs):
```bash
rsi-varlog /volume/case_2026/2026-0323-648596 \
    --rsi-file  /volume/case_2026/2026-0323-648596/20260323-MTSINARE-PE-01-RSI.log \
    --extract-dir /homes/annaw/rsi-extract/648596 \
    --var-log-dir /homes/annaw/rsi-extract/648596/20260323-MTSINARE-re0/var-re0 \
                  /homes/annaw/rsi-extract/648596/20260323-MTSINARE-re1/var-re1
```

### `--extract-dir`

By default the tool extracts case archives (`.tgz`, `.tar.gz`, `.zip`, …) **in the case directory itself**, creating one subfolder per archive.  This requires write permission on the case directory.

If the case directory is read-only (e.g. a shared volume under `/volume/CSdata/…`) or you simply prefer to keep it clean, pass `--extract-dir` to redirect extraction:

```bash
# Only load re0 var logs
rsi-varlog /volume/CSdata/annaw/case/<case-id> \
           --var-log-dir /homes/annaw/rsi-extract/<case-id>/re0-folder/var-re0

# Load both re0 and re1 (tool maps automatically by path content)
rsi-varlog /volume/CSdata/annaw/case/<case-id> \
           --var-log-dir /homes/annaw/rsi-extract/<case-id>/re0-folder/var-re0 \
                         /homes/annaw/rsi-extract/<case-id>/re1-folder/var-re1
```

| | Default (no `--extract-dir`) | With `--extract-dir` |
|---|---|---|
| Case directory permission needed | **read + write** | **read only** |
| Extract directory permission needed | n/a | **read + write** |
| Archives moved or copied? | moved into subfolders in case dir | copied into `--extract-dir` subfolders |
| Persistent across reboots? | yes | depends on chosen path (`/tmp`, `/dev/shm` are cleared on reboot) |

### `--rsi-file`

By default the tool automatically picks the RSI log file from the case directory (first match of `*RSI*.log`, `*RSI*.txt`, etc.).  Use `--rsi-file` to specify the exact file path, bypassing auto-detection:

```bash
rsi-varlog /volume/case_2026/2026-0323-648596 \
    --rsi-file /volume/case_2026/2026-0323-648596/20260323-MTSINARE-PE-01-RSI.log
```

### `--var-log-dir` — one or two paths

Pass **one path** to load only that RE's var logs.  Pass **two paths** to load both REs — the tool maps them automatically (the path containing `re1` in its name is treated as RE1, the other as RE0):

```bash
# One RE only
rsi-varlog /volume/case_2026/2026-0323-648596 \
    --var-log-dir /homes/annaw/rsi-extract/648596/20260323-MTSINARE-re0/var-re0

# Both REs
rsi-varlog /volume/case_2026/2026-0323-648596 \
    --var-log-dir /homes/annaw/rsi-extract/648596/20260323-MTSINARE-re0/var-re0 \
                  /homes/annaw/rsi-extract/648596/20260323-MTSINARE-re1/var-re1
```

## Development
```bash
uv sync --dev
uv run pytest
uv run ruff check rsi/
uv run ruff format rsi/
```
