Metadata-Version: 2.4
Name: rsi-varlog-explorer
Version: 1.5.4
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

A Juniper RSI (Request Support Information) and varlog explorer with an interactive Junos CLI simulator. Load a case directory and explore RSI output and var logs as if you were on the actual device, with tab completion, pipe commands, and contextual help.

This customized version is optimized for the JTAC daily workflow and introduces features that make the simulator experience much closer to a real Junos CLI:

- **Spacebar Completion**: Supports shortcut expansion (for example, typing `sh cha har` and pressing Space expands to `show chassis hardware`).
- **Contextual Help (`?`)**: Type `?` at any point to list available sub-commands (for example, `show chassis ?`).
- **Enhanced Config Mode**: Supports full hierarchical navigation, including `configure`, `edit`, and `show` within specific hierarchy levels.
- **Smart Output Filtering**: Automatically omits `no-forwarding` statements (for example, in `show chassis hardware`) for a cleaner view of auto-matched components.
- **Improved Pager Control**: Press `Ctrl+C` once to stop the pager and return to the CLI prompt. Press `Ctrl+C` a second time to exit the tool.

[![RSI CLI Demo](https://i.imgur.com/hWe8trh.gif)](https://github.hpe.com/ying-wang/rsi-varlog-explorer/raw/main/docs/media/Untitled_hq.mp4)

## Getting Started (New Users)

### Prerequisites

- Read permission on the case directory — required to read RSI files and archives
- Write permission on the case directory — required on first run if you do **not** use `--extract-dir` (the tool creates subfolders and extracts archives in place); if you use `--extract-dir`, the case directory only needs read permission
- **One device per case directory** — if a path contains RSI files or varlog archives for more than one device, move them into separate subdirectories before running the tool (e.g. `case/device-A/` and `case/device-B/`), otherwise the tool may mix up RSI data across devices
- SSH access to `p-jtac-lnx02`

On `p-jtac-lnx02`, verify Python 3.8+ is available:

```bash
ssh <your_username>@p-jtac-lnx02
python3 --version
```

If you see Python 3.8+, you're all set. If not, 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 (option A): Grant write permission to your case directory
# Default behaviour: the tool creates subfolders and extracts archives in the case
# directory itself on first run, so the directory must be writable.
chmod -R u+w /volume/CSdata/<your_username>/case/

# Step 6 (option B): Use --extract-dir to keep the case directory read-only
# If you cannot or do not want to write to the case directory, specify a
# separate writable directory with --extract-dir.  The tool will copy each
# archive into that directory and extract it there instead.
#   rsi-varlog /volume/CSdata/<your_username>/case/<case-id> \
#              --extract-dir /homes/<your_username>/rsi-extract/<case-id>
```

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

---

### Optional Setup (Python < 3.8 only)

If `python3 --version` shows < 3.8 on lnx02, 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
pip install rsi-varlog-explorer --user
```

### Usage

Point the tool at the case directory — it will auto-detect the RSI file and var logs:

```bash
rsi-varlog /volume/CSdata/<your_username>/case/<case-id>
```

### 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/
```
