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

Positive Look Behind Question #34

Closed
samcro1967 opened this issue May 15, 2022 · 16 comments
Closed

Positive Look Behind Question #34

samcro1967 opened this issue May 15, 2022 · 16 comments
Labels
bug Something isn't working

Comments

@samcro1967
Copy link

I am getting an error using a positive look behind. It works at https://regex101.com/. I tried various escapes for the ? and <. Any ideas?

Logs

panic: regexp: Compile(`(?<=\"version\":\s\")([0-9.]+)\"`): error parsing regexp: invalid or unsupported Perl syntax: `(?<`

Regex

(?<=\"version\":\s\")([0-9.]+)\"
@samcro1967 samcro1967 added the bug Something isn't working label May 15, 2022
@JosephKav
Copy link
Collaborator

@samcro1967
Copy link
Author

I think I got it to work correctly with the config below. However it is not showing up in the GUI as up to date, but as no successful query even though the data is in config.xml and matches. Tried it in incognito mode to rule out browser cache. Stopped and restarted the container. Removed and readded the container also. Very odd to me.

image

config.xml

  Sonarr/Sonarr:
    type: url
    url: http://services.sonarr.tv/v1/releases
    semantic_versioning: false
    url_commands:
      - type: regex
        regex: \"version\":\s\"([0-9.]+)\"
        index: 1
    web_url: http://'ocal.sonarr:8079/sonarr/system/updates
    icon: https://raw.githubusercontent.com/NX211/homer-icons/master/png/sonarr.png
    deployed_version:
      url: http://local.sonarr:8079/sonarr/api/v3/system/status?apikey=<redacted>
      json: version
    status:
      current_version: 3.0.8.1519
      current_version_timestamp: "2022-05-15T12:55:53Z"
      latest_version: 3.0.8.1519
      latest_version_timestamp: "2022-05-15T12:55:53Z"

@JosephKav
Copy link
Collaborator

So that regex fails with what's returned by the HTTP query. Turning the log level up to DEBUG, you can see that no spaces are returned in the JSON, so the \s part fails the regex, and omitting that, or making it optional with a ? work - \"version\":\s?\"([0-9.]+)\" or \"version\":\"([0-9.]+)\"

@samcro1967
Copy link
Author

Yes, that fixes the query issue, but back to figuring out another ay to strip off version with go's perl regex implementation.

image

@JosephKav
Copy link
Collaborator

JosephKav commented May 15, 2022

Ah, that you can fix by making the type regex_submatch. A use-case for regex would be when you want the 2nd regex match as regex_submatch will only match on the first

(regex ignores the matching brackets, regex_submatch uses those brackets. The index param wouldn't be needed here as regex_submatch forces it to be 1)

@samcro1967
Copy link
Author

Using regex_submatch gives me 3.0.8.1507 from v3-stable which is the first occurrence of the word version. I needed to use regex with index of 1 to get to the second match for v3-nightly.

http://services.sonarr.tv/v1/releases

I think the quickest path will be to write a bash script to curl the page, pull out what is needed, dump it to a text file, host it on a local web server, and get the latest version from there in Argus. Just have cron update it once an hour.

@JosephKav
Copy link
Collaborator

JosephKav commented May 15, 2022

Ah, the exact use-case for this regex command! The quickest solution would be to use your original regex url_command, then add another one that filters on that regex

    url_commands:
      - type: regex
        regex: \"version\":\s?\"[0-9.]+\"
        index: 1
      - type: regex_submatch
        regex: ([0-9.]+)

gives me the nightly version

❯ ./argus -config.file test.yml -test.service Sonarr/Sonarr
INFO: Testing (Sonarr/Sonarr), 
INFO: Sonarr/Sonarr, Latest Release - "3.0.8.1519"

(found that omitting the index causes a crash. I'll fix that! I remember adding a catch on start-up that told you it was missing at some point, but looks like I removed it for some reason. Probably when I was thinking of merging regex with regex_submatch, but didn't because of cases like this)

@JosephKav
Copy link
Collaborator

This PR fixes that index issue btw

@samcro1967
Copy link
Author

Yes, that did work. Didn't realize they could be stacked. That is a game changer. I have 5 apps working now. Looks like you added the discussion board. I could add them to the show and tell section if that would be of value.

@JosephKav
Copy link
Collaborator

JosephKav commented May 15, 2022

Yes, that did work. Didn't realize they could be stacked. That is a game changer. I have 5 apps working now. Looks like you added the discussion board. I could add them to the show and tell section if that would be of value.

Perfect!
Yeah, that'd definitely be interesting for me if you did please. Always nice to see people like you taking in an interest in what I've been working on and seeing how other people use it

@samcro1967
Copy link
Author

Just added what I have so far.

@samcro1967
Copy link
Author

@JosephKav I noticed today Sonarr stopped working. When I have semantic versioning set to false I get:

No version matching the conditions specified could be found for "Sonarr/Sonarr" at "http://services.sonarr.tv/v1/releases"

If I comment it out, I then get:

ERROR: Testing (Sonarr/Sonarr), failed converting "3.0.8.1520" to a semantic version. If all versions are in this style, consider adding json/regex to get the version into the style of 'MAJOR.MINOR.PATCH' (https://semver.org/), or disabling semantic versioning (globally with defaults.service.semantic_versioning or just for this service with the semantic_versioning var)
ERROR: Testing (Sonarr/Sonarr), failed converting "3.0.8.1520" to a semantic version. If all versions are in this style, consider adding json/regex to get the version into the style of 'MAJOR.MINOR.PATCH' (https://semver.org/), or disabling semantic versioning (globally with defaults.service.semantic_versioning or just for this service with the semantic_versioning var)

So it seems like the regex is working as it is finding the right version of 3.0.8.1520. This worked yesterday. Possibly one of the updates is impacting this?

Current config.xml

  Sonarr/Sonarr:
    type: url
    url: http://services.sonarr.tv/v1/releases
    semantic_versioning: false
    url_commands:
      - type: regex
        regex: \"version\":\s\"([0-9.]+)\"
        index: 1
      - type: regex
        regex: '[0-9.]+'
    web_url: http://local.sonarr:8079/sonarr/system/updates
    icon: https://raw.githubusercontent.com/NX211/homer-icons/master/png/sonarr.png
    deployed_version:
      url: http://local.sonarr:8079/sonarr/api/v3/system/status?apikey=<redacted>
      json: version

@samcro1967 samcro1967 reopened this May 16, 2022
@JosephKav
Copy link
Collaborator

JosephKav commented May 16, 2022

Hmm, It looks like maybe you're just missing the ? on the \s. Not sure why commenting out progressive_versioning shows the version, because that RegEx should fail.

❯ ./argus -test.service Sonarr/Sonarr
INFO: Testing (Sonarr/Sonarr),
ERROR: Sonarr/Sonarr, failed converting "3.0.8.1520" to a semantic version. If all versions are in this style, consider adding url_commands to get the version into the style of 'MAJOR.MINOR.PATCH' (https://semver.org/), or disabling semantic versioning (globally with defaults.service.semantic_versioning or just for this service with the semantic_versioning var)
ERROR: Testing (Sonarr/Sonarr), No version matching the conditions specified could be found for "Sonarr/Sonarr" at "http://services.sonarr.tv/v1/releases"

❯ nano config.yml - disable progressive_versioning
❯ ./argus -test.service Sonarr/Sonarr
INFO: Testing (Sonarr/Sonarr),
INFO: Sonarr/Sonarr, Latest Release - "3.0.8.1520"

❯ nano config.yml - remove the ? from the regex
❯ ./argus -test.service Sonarr/Sonarr
INFO: Testing (Sonarr/Sonarr),
ERROR: Testing (Sonarr/Sonarr), No version matching the conditions specified could be found for "Sonarr/Sonarr" at "http://services.sonarr.tv/v1/releases"

and btw, that second url_command can be removed once you add the ? (if you're using the master branch. I'm just trying to get these other notifications working with Shoutrrr, then I'll do another release, probably major this time)

@samcro1967
Copy link
Author

Yup. Guess I just cannot wrap my head around why the ? is needed so I keep leaving it out. The \s takes care of the space and the \" takes care of the quote. There is nothing else between them to match. But let's not go down that regex rabbit hole. LOL.

Also commented out the second regex and it works as expected.

@JosephKav
Copy link
Collaborator

JosephKav commented May 16, 2022

Yup. Guess I just cannot wrap my head around why the ? is needed so I keep leaving it out. The \s takes care of the space and the \" takes care of the quote. There is nothing else between them to match. But let's not go down that regex rabbit hole. LOL.

Also commented out the second regex and it works as expected.

This issue with the RegEx is that the spaces that appear in our browsers aren't there if you curl the url or when Go does the equivalent.
The ? is just an alternative to removing the \s. You may prefer the \s? in-case you ever want to test again, as you can just go to the site and copy it with/without the spaces and the RegEx will work

@JosephKav
Copy link
Collaborator

❯ curl https://services.sonarr.tv/v1/releases
{"v3-stable":{"releaseChannel":"v3-stable","majorVersion":3,"status":"supported","version":"3.0.8.1507",

Using the stable version, the string we'll do the RegEx on is ..."version":"3.0.8.1507"..., so with that regex of \"version\":\s\"([0-9.]+)\",

Up to \"version\": matches "version":, but then the next character is a " which doesn't match the \s in the RegEx. So we avoid this by making that \s optional with the ?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants