Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue running ksconf sort #95

Open
EdGarrity opened this issue Jan 25, 2023 · 7 comments
Open

Issue running ksconf sort #95

EdGarrity opened this issue Jan 25, 2023 · 7 comments
Assignees

Comments

@EdGarrity
Copy link

The problem

We are having issues using ksconf to sort a conf file. When we run the script following the instructions, we get an error message as if the script does not recognize the sort command.

Environment

  • Ksconf version: (Grab the first 2 text lines of output after running ksconf --version)

ksconf 0.9.2 (Build 1043)
Python: 3.7.11 (D:\Program Files\Splunk\bin\python3.exe)

  • OS & version used:
    OS Name: Microsoft Windows 10 Enterprise
    OS Version: 10.0.19044 N/A Build 19044
    OS Manufacturer: Microsoft Corporation
    OS Configuration: Member Workstation
    OS Build Type: Multiprocessor Free

  • Python version:
    Python 3.7.11

  • Installed via: (pip, git, Splunk app, or so on)
    Installed via Splunk app

Details

Running "ksconf sort --inplace *.conf" produces the following output:

D:\Temp\Splunk>dir
 Volume in drive D is Data
 Volume Serial Number is 3A1E-0FE8

 Directory of D:\Temp\Splunk

01/25/2023  05:44 PM    <DIR>          .
01/25/2023  05:44 PM    <DIR>          ..
12/13/2022  03:04 PM               511 workflow_actions.conf
               1 File(s)            511 bytes
               2 Dir(s)  773,047,701,504 bytes free

D:\Temp\Splunk>type *.conf

workflow_actions.conf


#   Version 9.0.3
[show_source]
type=link
fields = _cd
display_location = event_menu
label = Show Source
link.uri = /app/$@namespace$/show_source?sid=$@sid$&offset=$@offset$&latest_time=$@latest_time$

[ifx]
type = link
display_location = event_menu
label = Extract Fields
link.uri = /app/$@namespace$/field_extractor?sid=$@sid$&offset=$@offset$

[etb]
type = link
display_location = event_menu
label = Build Event Type
link.uri = /etb?sid=$@sid$&offset=$@offset$&namespace=$@namespace$


D:\Temp\Splunk>ksconf sort --inplace *.conf
usage: ksconf [-h] [--version] [--force-color] [--disable-color]
              {check,combine,diff,filter,merge,minimize,package,promote,rest-export,rest-publish,snapshot,sort,unarchive,xml-format}
              ...
ksconf: error: invalid choice: 'sort --inplace *.conf' (choose from 'check', 'combine', 'diff', 'filter', 'merge', 'minimize', 'package', 'promote', 'rest-export', 'rest-publish', 'snapshot', 'sort', 'unarchive', 'xml-format')

D:\Temp\Splunk>
@lowell80 lowell80 self-assigned this Jan 26, 2023
@lowell80
Copy link
Member

lowell80 commented Jan 26, 2023

This is odd. It seems like some kind of argument parsing issue. It looks like it's seeing sort --inplace *.conf as a single argument.

What output do you get if you run these two commands?

ksconf sort
ksconf sort --help

Also, are you using a command prompt or powershell?

@EdGarrity
Copy link
Author

EdGarrity commented Jan 31, 2023 via email

@lowell80
Copy link
Member

lowell80 commented Feb 7, 2023

Unfortunately I don't have a Windows machine at my fingertips to run a quick test on. I do have some unit tests in place that do some simple sorts and other tests that should fail if this argument parsing behavior is broken more broadly. (which seems to be the case here. I'm guessing that ksconf check *.conf is failing for you too.). Testing is done using plain vanilla version of python (rather than the version embedded with Splunk) but it should work the same unless something is broken with the Splunk install. It seems like there's an issue with basic argument parsing, which seems quite odd.

I'll see if I can test at some point soon but these feels like an environmental issue more than a code problem.... In the mean time, can you answer/check any of the following:

  • Do you have the same behavior if you attempt to run the command from a PowerShell prompt?
  • Do you have more than one machine you can test this on?
  • What version of Splunk are you using? Do you have the same problem if you use a standalone Python install? (rather than using the embedded Python that ships with Splunk)

@EdGarrity
Copy link
Author

EdGarrity commented Feb 18, 2023 via email

@pmeyerson
Copy link

pmeyerson commented Feb 18, 2023

BTW, was not able to replicate this on my own windows10 desktop at home, using both the Command Prompt and Windows PS. Also worked fine using WSL2. Splunk is not installed.

I am using Windows Terminal version 1.16.10261.0, the latest from the Microsoft store, so maybe try that if you haven't already @EdGarrity

Microsoft Windows [Version 10.0.19044.2251]

Installed KSCONF 0.10.0b7
python 3.7.2


mkdir test
cd test
pip install virtualenv
python -m venv .venv
pip install ksconf

echo "[default]" >> a.conf
echo ["default]" >> b.conf
ksconf sort --inplace *.conf

(.venv) C:\Users\phil\Documents\repos\ktest> ksconf sort --inplace *.conf
Error trying to process file a.conf.  Error:  Unexpected entry:  '"[general]" '
Error trying to process file b.conf.  Error:  Unexpected entry:  '"[Default]" '

@pmeyerson
Copy link

pmeyerson commented Feb 18, 2023

Ah, found v0.9.2 by the old name, can't replicate this issue with kintyre_splunk_conf 0.9.2 either:
EDIT: works as expected since its a dummy test file

(.venv) C:\Users\phil\Documents\repos\ktest>ksconf sort --inplace *.conf
Error trying to process file a.conf.  Error:  Unexpected entry:  '"[general]" '
Replaced file a.conf with sorted content.
Error trying to process file b.conf.  Error:  Unexpected entry:  '"[Default]" '
Replaced file b.conf with sorted content.

@EdGarrity
Copy link
Author

EdGarrity commented Feb 19, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants