* How to configure smartd and send notifications? [not found] <4D873504-6540-477A-A2DB-DE293395CAFC.ref@ymail.com> @ 2024-05-19 22:48 ` Tristan Kohl via 2024-05-20 11:30 ` Felix Lechner via 0 siblings, 1 reply; 12+ messages in thread From: Tristan Kohl via @ 2024-05-19 22:48 UTC (permalink / raw) To: help-guix Hello Guix gurus, I have a hard time wrapping my head around how to configure smartd (1) and send notifications via ntfy.sh (2). 1. Configuration of smartd I could not find anything in the admin module in the Guix repository on how to configure smartd (i.e. smartd-configuration) - there I found only smartmontools build procedure. When checking /var/log/messages I could see that smartd defaults to some configuration file in the store rather than the default /etc/smartd.conf. So I tried to write my own: (define smartd-send-ntfy (plain-file "/usr/local/sbin/send-ntfy" "#!/bin/sh\ncurl ntfy.sh/<my-topic> -d 'curl -Ls -H "Title: $SMARTD_SUBJECT" -d "$SMARTD_FAILTYPE Device: $SMARTD_DEVICE Time: $SMARTD_TFIRST Message: $SMARTD_FULLMESSAGE"')) (define smartd-config-file (plain-file "smartd.conf" "DEVICESCAN -a -s (S/../.././03|L/../01/./04) -m <nomailer> -M exec /usr/local/sbin/send-ntfy -M test")) (services (append (list ... (simple-service 'smartd-service shepherd-root-service-type (list (shepherd-service (documentation "Monitor disks for failure.") (provision '(smartd)) (requirement '(udev user-processes)) (start #~(make-forkexec-constructor (list "/run/current-system/profile/sbin/smartd" "--no-fork" "-c" smartd-config-file))) (stop #~(make-kill-destructor)))))) %base-services)) This results in a warning "possibly unbound variable `smartd-config-file". Tried to understand G-expressions and put #$smartd-config-file in there but I am already overwhelmed with (un)quote so I guess I am missing the point here. Also how do I get the store path from smartd-notify-send into smartd-config-file because my naive approach putting the path into plain-file name argument does not work. 2. Notifications Also I have a bunch of mcron jobs which I also would like to use ntfy.sh to send messages to me. How do I append a string to the srcub job passing a message to msg? Is this even the right way? (define (notify msg) (string-append "curl ntfy.sh/sTu0vFzNZqfMSLJiRAxuTHEUHy8BYWW6 -d '" msg "'")) (define monthly-srub-job #~(job "0 3 1 * *" "btrfs scrub start -dB /pool" )) Sorry for these beginner questions, I just started diverting from copy-pasting config parts from others. Thank you! ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-19 22:48 ` How to configure smartd and send notifications? Tristan Kohl via @ 2024-05-20 11:30 ` Felix Lechner via 2024-05-20 13:56 ` Tristan Kohl via 0 siblings, 1 reply; 12+ messages in thread From: Felix Lechner via @ 2024-05-20 11:30 UTC (permalink / raw) To: Tristan Kohl, help-guix Hi Tristan, On Mon, May 20 2024, Tristan Kohl via wrote: > (list "/run/current-system/profile/sbin/smartd" "--no-fork" "-c" smartd-config-file))) > warning "possibly unbound variable smartd-config-file". Please quoteg the variable smartd-config-file as #$smartd-config-file inside the G-expression. Did it work? Kind regards Felix ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-20 11:30 ` Felix Lechner via @ 2024-05-20 13:56 ` Tristan Kohl via 2024-05-20 15:04 ` Felix Lechner via 0 siblings, 1 reply; 12+ messages in thread From: Tristan Kohl via @ 2024-05-20 13:56 UTC (permalink / raw) To: help-guix Hello Felix, it works, thank you! Though I could have sworn I tried this last night... @all Does anyone know how I would receive the store path from the generated smartd-send-ntfy script so I can pass it to smartd-config-file? I did mess around a bit more and I think I am closer to the solution by now: (define smartd-send-ntfy "send-ntfy" "#!/bin/sh\ncurl ...")) (define smartd-config-file (plain-file "smartd.conf" (string-append "... -M exec " smartd-send-ntfy))) On 20 May 2024 13:30:52 CEST, Felix Lechner <felix.lechner@lease-up.com> wrote: >Hi Tristan, > >On Mon, May 20 2024, Tristan Kohl via wrote: > >> (list "/run/current-system/profile/sbin/smartd" "--no-fork" "-c" smartd-config-file))) >> warning "possibly unbound variable smartd-config-file". > >Please quoteg the variable smartd-config-file as #$smartd-config-file >inside the G-expression. Did it work? > >Kind regards >Felix ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-20 13:56 ` Tristan Kohl via @ 2024-05-20 15:04 ` Felix Lechner via 2024-05-20 19:15 ` Tristan Kohl via 0 siblings, 1 reply; 12+ messages in thread From: Felix Lechner via @ 2024-05-20 15:04 UTC (permalink / raw) To: Tristan Kohl, help-guix Hi Tristan, On Mon, May 20 2024, Tristan Kohl via wrote: > (define smartd-config-file > (plain-file Have you tried mixed-text-file? Kind regards Felix ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-20 15:04 ` Felix Lechner via @ 2024-05-20 19:15 ` Tristan Kohl via 2024-05-20 23:42 ` Felix Lechner via 0 siblings, 1 reply; 12+ messages in thread From: Tristan Kohl via @ 2024-05-20 19:15 UTC (permalink / raw) To: help-guix Hello Felix, Indee I did. But even though it results in the correct path, smartd then complains that the file is not executable... local-file does not work either even though a external file fixes the executable issue. Here it complains about not finding /bin/sh which otoh can be fixed in mixed-text-file by replacing the shebang with "#/!" bash "/bin/sh". So I am stuck between local-file which does not find the interpreter and mixed-text-file which does not make the file executable. I guess I will have to step back from the plan as there are too many roadblocks and I wasted three days on this already. Thank you nontheless, I very much appreciate the help! On 20 May 2024 17:04:14 CEST, Felix Lechner <felix.lechner@lease-up.com> wrote: >Hi Tristan, > >On Mon, May 20 2024, Tristan Kohl via wrote: > >> (define smartd-config-file >> (plain-file > >Have you tried mixed-text-file? > >Kind regards >Felix ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-20 19:15 ` Tristan Kohl via @ 2024-05-20 23:42 ` Felix Lechner via 2024-05-21 15:33 ` Tristan Kohl via 0 siblings, 1 reply; 12+ messages in thread From: Felix Lechner via @ 2024-05-20 23:42 UTC (permalink / raw) To: Tristan Kohl, help-guix Hi Tristan, On Mon, May 20 2024, Tristan Kohl via wrote: > smartd then complains that the file is not executable... Sorry, it was a Monday morning for me. If you are comfortable using Guile---which I'm sure you almost are by now--You can use 'program-file': Please have a look at any of these hooks on one of my systems. [1] An untested version of your script might look something like this, although I probably got some of the quoting wrong---either in Scheme or in your command. (define smartd-send-ntfy (program-file "send-ntfy" #~((let* ((subject (getenv "SMARTD_SUBJECT)) (device (getenv "SMARTD_DEVICE)) (failure-type (getenv "SMARTD_FAILTYPE)) (timestamp (getenv "SMARTD_TFIRST")) (message (getenv "SMARTD_MESSAGE"))) (system* "curl" "ntfy.sh/<my-topic>" "-d" (string-join `("curl" "-Ls" "-H" ,(string-append "Title: " subject) "-d" ,subject "-d" ,(string-append "'" (string-join (list "Device:" device "Time:" timestamp "Message:" message)) "'")))))))) Kind regards Felix [1] https://codeberg.org/lechner/system-config/src/commit/215fc20a29e553fd8108ba737d557ecb98279540/host/wallace-server/operating-system.scm#L1134-L1168 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-20 23:42 ` Felix Lechner via @ 2024-05-21 15:33 ` Tristan Kohl via 2024-05-21 15:50 ` Tomas Volf 0 siblings, 1 reply; 12+ messages in thread From: Tristan Kohl via @ 2024-05-21 15:33 UTC (permalink / raw) To: help-guix Hello Felix, my last message was not to critizise your help but rather my frustration with my own limited progress. I really appreciate the help! program-file at least results in a usable thing however since the script gets executed by smard I get the "command not found" in my logs. It seems like curl is not in PATH for smartd. Do I need to import something into the gexp? Also those env variables are defined by smartd during runtime depending on which drive produced the error. Therefore I need shell expansion/env variables and have to use system (without *) imho. This is the current state: (define-smartd-send-ntfy (program-file "send-ntfy" #~(system (string-append "curl " "-H \"Title: $SMARTD_SUBJECT\" " ...)))) Note: when using system* the error is: In execvp of curl: No such file or directory Thanks for bearing with me! Tristan On 21 May 2024 01:42:02 CEST, Felix Lechner <felix.lechner@lease-up.com> wrote: >Hi Tristan, > >On Mon, May 20 2024, Tristan Kohl via wrote: > >> smartd then complains that the file is not executable... > >Sorry, it was a Monday morning for me. > >If you are comfortable using Guile---which I'm sure you almost are by >now--You can use 'program-file': > >Please have a look at any of these hooks on one of my systems. [1] > >An untested version of your script might look something like this, >although I probably got some of the quoting wrong---either in Scheme or >in your command. > >(define smartd-send-ntfy > (program-file "send-ntfy" > #~((let* ((subject (getenv "SMARTD_SUBJECT)) > (device (getenv "SMARTD_DEVICE)) > (failure-type (getenv "SMARTD_FAILTYPE)) > (timestamp (getenv "SMARTD_TFIRST")) > (message (getenv "SMARTD_MESSAGE"))) > (system* "curl" > "ntfy.sh/<my-topic>" > "-d" (string-join > `("curl" > "-Ls" > "-H" ,(string-append "Title: " subject) > "-d" ,subject > "-d" ,(string-append > "'" > (string-join (list "Device:" device > "Time:" timestamp > "Message:" message)) > "'")))))))) > >Kind regards >Felix > >[1] https://codeberg.org/lechner/system-config/src/commit/215fc20a29e553fd8108ba737d557ecb98279540/host/wallace-server/operating-system.scm#L1134-L1168 ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-21 15:33 ` Tristan Kohl via @ 2024-05-21 15:50 ` Tomas Volf 2024-05-23 19:25 ` Tristan Kohl via 0 siblings, 1 reply; 12+ messages in thread From: Tomas Volf @ 2024-05-21 15:50 UTC (permalink / raw) To: Tristan Kohl; +Cc: help-guix [-- Attachment #1: Type: text/plain, Size: 1434 bytes --] On 2024-05-21 17:33:24 +0200, Tristan Kohl via wrote: > Hello Felix, > > my last message was not to critizise your help but rather my frustration with my own limited progress. I really appreciate the help! > > program-file at least results in a usable thing however since the script gets executed by smard I get the "command not found" in my logs. It seems like curl is not in PATH for smartd. Do I need to import something into the gexp? > > Also those env variables are defined by smartd during runtime depending on which drive produced the error. Therefore I need shell expansion/env variables and have to use system (without *) imho. > > This is the current state: > > (define-smartd-send-ntfy > (program-file "send-ntfy" > #~(system > (string-append "curl " "-H \"Title: $SMARTD_SUBJECT\" " ...)))) Ignoring the obvious quoting issues here (what Felix does with `getenv' seems much safer, and should produce the same result?), > > Note: when using system* the error is: > In execvp of curl: No such file or directory This should be solvable by using `file-append', so, basing on the system* variant, something like: #~(system* #$(file-append curl "/bin/curl") <other-arguments-here>) Should invoke curl by absolute path. (You need import (gnu packages curl) of course.) Hope this helps, Tomas -- There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-21 15:50 ` Tomas Volf @ 2024-05-23 19:25 ` Tristan Kohl via 2024-05-24 4:10 ` Felix Lechner via 2024-05-24 10:19 ` Tomas Volf 0 siblings, 2 replies; 12+ messages in thread From: Tristan Kohl via @ 2024-05-23 19:25 UTC (permalink / raw) To: help-guix Well look at me. So focused in my old ways on constructing a shell script that I did not even think about using Guile as the executable :D Thank you Thomas an Felix for your pointers! I read up about G-Expressions and got it almost working. But I must miss something because when executing the build result it makes the request successfully (checked return of http-get with pk and logs on the server) but still fails with this error: Backtrace: 0 (primitive-load "/gnu/store/9gjnc0p...") ERROR: In procedure primitive-load: Wrong type to apply: #<unspecified> (use-module (gnu) (guix modules)) (use-package-modules tls) (define smartd-send-ntfy (program-file "smartd-send-ntfy" (with-extensions (list gnutls) (with-imported-modules (source-module-closure '((web client))) #~((use-modules (web client)) (http-get "https://example.com")))))) On 21 May 2024 17:50:27 CEST, Tomas Volf <~@wolfsden.cz> wrote: >On 2024-05-21 17:33:24 +0200, Tristan Kohl via wrote: >> Hello Felix, >> >> my last message was not to critizise your help but rather my frustration with my own limited progress. I really appreciate the help! >> >> program-file at least results in a usable thing however since the script gets executed by smard I get the "command not found" in my logs. It seems like curl is not in PATH for smartd. Do I need to import something into the gexp? >> >> Also those env variables are defined by smartd during runtime depending on which drive produced the error. Therefore I need shell expansion/env variables and have to use system (without *) imho. >> >> This is the current state: >> >> (define-smartd-send-ntfy >> (program-file "send-ntfy" >> #~(system >> (string-append "curl " "-H \"Title: $SMARTD_SUBJECT\" " ...)))) > >Ignoring the obvious quoting issues here (what Felix does with `getenv' seems >much safer, and should produce the same result?), > >> >> Note: when using system* the error is: >> In execvp of curl: No such file or directory > >This should be solvable by using `file-append', so, basing on the system* >variant, something like: > > #~(system* #$(file-append curl "/bin/curl") <other-arguments-here>) > >Should invoke curl by absolute path. (You need import (gnu packages curl) of >course.) > >Hope this helps, >Tomas > >-- >There are only two hard things in Computer Science: >cache invalidation, naming things and off-by-one errors. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-23 19:25 ` Tristan Kohl via @ 2024-05-24 4:10 ` Felix Lechner via 2024-05-24 10:19 ` Tomas Volf 1 sibling, 0 replies; 12+ messages in thread From: Felix Lechner via @ 2024-05-24 4:10 UTC (permalink / raw) To: Tristan Kohl, help-guix Hi Tristan, On Thu, May 23 2024, Tristan Kohl via wrote: > I did not even think about using Guile as the executable :D Congratulations! Maybe you will stop writing shell scripts altogether. > Wrong type to apply: #<unspecified> For me, that error often means an extra pair of parentheses, such as trying to evaluate a constant, but here the issue could be that http-get returns two values. [1] Maybe this works without an error? (use-module (gnu) (guix modules)) (use-package-modules tls) (define smartd-send-ntfy (program-file "smartd-send-ntfy" (with-extensions (list gnutls) (with-imported-modules (source-module-closure '((ice-9 receive) (web client))) #~((use-modules (ice-9 receive) (web client)) (receive (_ body) (http-get "https://example.com") body))))) Instead of the string body, you could return a success value via something like (not (string-null? body)) You can look at the values in the comfort of the Guile REPL, or in Emacs Geiser. Kind regards Felix [1] https://www.gnu.org/software/guile//manual/html_node/Multiple-Values.html ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-23 19:25 ` Tristan Kohl via 2024-05-24 4:10 ` Felix Lechner via @ 2024-05-24 10:19 ` Tomas Volf 2024-05-31 13:42 ` Tristan Kohl via 1 sibling, 1 reply; 12+ messages in thread From: Tomas Volf @ 2024-05-24 10:19 UTC (permalink / raw) To: Tristan Kohl; +Cc: help-guix [-- Attachment #1: Type: text/plain, Size: 7242 bytes --] On 2024-05-23 21:25:08 +0200, Tristan Kohl via wrote: > Well look at me. So focused in my old ways on constructing a shell script that I did not even think about using Guile as the executable :D > > Thank you Thomas an Felix for your pointers! > > I read up about G-Expressions and got it almost working. But I must miss something because when executing the build result it makes the request successfully (checked return of http-get with pk and logs on the server) but still fails with this error: > > Backtrace: > 0 (primitive-load "/gnu/store/9gjnc0p...") > > ERROR: In procedure primitive-load: > Wrong type to apply: #<unspecified> > > > (use-module (gnu) (guix modules)) > (use-package-modules tls) > > (define smartd-send-ntfy > (program-file "smartd-send-ntfy" > (with-extensions (list gnutls) > (with-imported-modules > (source-module-closure '((web client))) > #~((use-modules (web client)) > (http-get "https://example.com")))))) I think g-exp needs to be a single expression. In other words, add `begin' in there. In your code you are basically trying to apply result of `(use-modules ...)' to result of `(http-get ...)'. Since use-modules do not return anything, you get the error above. You can test it using just plain guile and you will get the same error: guile -c '((use-modules (web client)) (http-get "https://example.org"))' I think this should work: (define smartd-send-ntfy (program-file "smartd-send-ntfy" (with-extensions (list gnutls) (with-imported-modules (source-module-closure '((web client))) #~(begin (use-modules (web client)) (http-get "https://example.com")))))) Your original code: $ guix repl Loading Guix REPL meta-commands... Increasing build verbosity... Disabling grafting... GNU Guile 3.0.9 Copyright (C) 1995-2023 Free Software Foundation, Inc. Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it under certain conditions; type `,show c' for details. Enter `,help' for help. scheme@(guix-user)> ,use (guix) scheme@(guix-user)> #~((use-modules (web client)) (http-get "https://example.com")) $1 = #<gexp ((use-modules (web client)) (http-get "https://example.com")) 7f6c48696720> scheme@(guix-user)> (program-file "test" $1) $2 = #<<program-file> name: "test" gexp: #<gexp ((use-modules (web client)) (http-get "https://example.com")) 7f6c48696720> guile: #f path: ("/gnu/store/ff1cyww9qlra4849q6k0n30w7q67ziim-guix-module-union/share/guile/site/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile" "/home/wolf/.guix-home/profile/share/guile/site/3.0" "/run/current-system/profile/share/guile/site/3.0")> scheme@(guix-user)> ,lower $2 $3 = #<derivation /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv => /gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test 7f6c35dd5d70> scheme@(guix-user)> ,build $3 building /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv... successfully built /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv $4 = "/gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test" scheme@(guix-user)> (system $4) Backtrace: 0 (primitive-load "/gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test") ERROR: In procedure primitive-load: Wrong type to apply: #<unspecified> $5 = 256 Now with the `begin': scheme@(guix-user)> #~(begin (use-modules (web client)) (http-get "https://example.com")) $6 = #<gexp (begin (use-modules (web client)) (http-get "https://example.com")) 7f6c35e61a20> scheme@(guix-user)> (program-file "test" $6) $7 = #<<program-file> name: "test" gexp: #<gexp (begin (use-modules (web client)) (http-get "https://example.com")) 7f6c35e61a20> guile: #f path: ("/gnu/store/ff1cyww9qlra4849q6k0n30w7q67ziim-guix-module-union/share/guile/site/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile" "/home/wolf/.guix-home/profile/share/guile/site/3.0" "/run/current-system/profile/share/guile/site/3.0" "/gnu/store/s2cf4ibjw0g6npx0ia54x5xg6hzangn7-wolfsden/share/guile/site/3.0" "/gnu/store/czkzwa77lr39ayj016vhqrbhf2da2isr-nonguix/share/guile/site/3.0")> scheme@(guix-user)> ,lower $7 $8 = #<derivation /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv => /gnu/store/7ylpw11r0sbdc2z02sir5gcr552dqks6-test 7f6c3606cb40> scheme@(guix-user)> ,build $8 building /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv... successfully built /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv $9 = "/gnu/store/7ylpw11r0sbdc2z02sir5gcr552dqks6-test" scheme@(guix-user)> (system $9) $10 = 0 > > > On 21 May 2024 17:50:27 CEST, Tomas Volf <~@wolfsden.cz> wrote: > >On 2024-05-21 17:33:24 +0200, Tristan Kohl via wrote: > >> Hello Felix, > >> > >> my last message was not to critizise your help but rather my frustration with my own limited progress. I really appreciate the help! > >> > >> program-file at least results in a usable thing however since the script gets executed by smard I get the "command not found" in my logs. It seems like curl is not in PATH for smartd. Do I need to import something into the gexp? > >> > >> Also those env variables are defined by smartd during runtime depending on which drive produced the error. Therefore I need shell expansion/env variables and have to use system (without *) imho. > >> > >> This is the current state: > >> > >> (define-smartd-send-ntfy > >> (program-file "send-ntfy" > >> #~(system > >> (string-append "curl " "-H \"Title: $SMARTD_SUBJECT\" " ...)))) > > > >Ignoring the obvious quoting issues here (what Felix does with `getenv' seems > >much safer, and should produce the same result?), > > > >> > >> Note: when using system* the error is: > >> In execvp of curl: No such file or directory > > > >This should be solvable by using `file-append', so, basing on the system* > >variant, something like: > > > > #~(system* #$(file-append curl "/bin/curl") <other-arguments-here>) > > > >Should invoke curl by absolute path. (You need import (gnu packages curl) of > >course.) > > > >Hope this helps, > >Tomas > > > >-- > >There are only two hard things in Computer Science: > >cache invalidation, naming things and off-by-one errors. Have a nice day, Tomas -- There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: How to configure smartd and send notifications? 2024-05-24 10:19 ` Tomas Volf @ 2024-05-31 13:42 ` Tristan Kohl via 0 siblings, 0 replies; 12+ messages in thread From: Tristan Kohl via @ 2024-05-31 13:42 UTC (permalink / raw) To: help-guix Thank you Thomas and Felix for your patience! @Thomas, this was the solution! Works like a charm now :) On 24 May 2024 12:19:39 CEST, Tomas Volf <~@wolfsden.cz> wrote: >On 2024-05-23 21:25:08 +0200, Tristan Kohl via wrote: >> Well look at me. So focused in my old ways on constructing a shell script that I did not even think about using Guile as the executable :D >> >> Thank you Thomas an Felix for your pointers! >> >> I read up about G-Expressions and got it almost working. But I must miss something because when executing the build result it makes the request successfully (checked return of http-get with pk and logs on the server) but still fails with this error: >> >> Backtrace: >> 0 (primitive-load "/gnu/store/9gjnc0p...") >> >> ERROR: In procedure primitive-load: >> Wrong type to apply: #<unspecified> >> >> >> (use-module (gnu) (guix modules)) >> (use-package-modules tls) >> >> (define smartd-send-ntfy >> (program-file "smartd-send-ntfy" >> (with-extensions (list gnutls) >> (with-imported-modules >> (source-module-closure '((web client))) >> #~((use-modules (web client)) >> (http-get "https://example.com")))))) > >I think g-exp needs to be a single expression. In other words, add `begin' in >there. In your code you are basically trying to apply result of `(use-modules >...)' to result of `(http-get ...)'. Since use-modules do not return anything, >you get the error above. You can test it using just plain guile and you will >get the same error: > > guile -c '((use-modules (web client)) (http-get "https://example.org"))' > >I think this should work: > > (define smartd-send-ntfy > (program-file "smartd-send-ntfy" > (with-extensions (list gnutls) > (with-imported-modules > (source-module-closure '((web client))) > #~(begin (use-modules (web client)) > (http-get "https://example.com")))))) > >Your original code: > > $ guix repl > Loading Guix REPL meta-commands... > Increasing build verbosity... > Disabling grafting... > GNU Guile 3.0.9 > Copyright (C) 1995-2023 Free Software Foundation, Inc. > > Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. > This program is free software, and you are welcome to redistribute it > under certain conditions; type `,show c' for details. > > Enter `,help' for help. > scheme@(guix-user)> ,use (guix) > scheme@(guix-user)> #~((use-modules (web client)) (http-get "https://example.com")) > $1 = #<gexp ((use-modules (web client)) (http-get "https://example.com")) 7f6c48696720> > scheme@(guix-user)> (program-file "test" $1) > $2 = #<<program-file> name: "test" gexp: #<gexp ((use-modules (web client)) (http-get "https://example.com")) 7f6c48696720> guile: #f path: ("/gnu/store/ff1cyww9qlra4849q6k0n30w7q67ziim-guix-module-union/share/guile/site/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile" "/home/wolf/.guix-home/profile/share/guile/site/3.0" "/run/current-system/profile/share/guile/site/3.0")> > scheme@(guix-user)> ,lower $2 > $3 = #<derivation /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv => /gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test 7f6c35dd5d70> > scheme@(guix-user)> ,build $3 > building /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv... > successfully built /gnu/store/x3rkbl47j83d5ps8r8a915blks6hfbin-test.drv > $4 = "/gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test" > scheme@(guix-user)> (system $4) > Backtrace: > 0 (primitive-load "/gnu/store/50m45lc93x7fayaq3y7kzi2zhjz7qwdz-test") > > ERROR: In procedure primitive-load: > Wrong type to apply: #<unspecified> > $5 = 256 > >Now with the `begin': > > scheme@(guix-user)> #~(begin (use-modules (web client)) (http-get "https://example.com")) > $6 = #<gexp (begin (use-modules (web client)) (http-get "https://example.com")) 7f6c35e61a20> > scheme@(guix-user)> (program-file "test" $6) > $7 = #<<program-file> name: "test" gexp: #<gexp (begin (use-modules (web client)) (http-get "https://example.com")) 7f6c35e61a20> guile: #f path: ("/gnu/store/ff1cyww9qlra4849q6k0n30w7q67ziim-guix-module-union/share/guile/site/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site/3.0" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile/site" "/gnu/store/1gd9nsy4cps8fnrd1avkc9l01l7ywiai-guile-3.0.9/share/guile" "/home/wolf/.guix-home/profile/share/guile/site/3.0" "/run/current-system/profile/share/guile/site/3.0" "/gnu/store/s2cf4ibjw0g6npx0ia54x5xg6hzangn7-wolfsden/share/guile/site/3.0" "/gnu/store/czkzwa77lr39ayj016vhqrbhf2da2isr-nonguix/share/guile/site/3.0")> > scheme@(guix-user)> ,lower $7 > $8 = #<derivation /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv => /gnu/store/7ylpw11r0sbdc2z02sir5gcr552dqks6-test 7f6c3606cb40> > scheme@(guix-user)> ,build $8 > building /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv... > successfully built /gnu/store/7xcnijz3cf4231sdg0df5hig259k38nf-test.drv > $9 = "/gnu/store/7ylpw11r0sbdc2z02sir5gcr552dqks6-test" > scheme@(guix-user)> (system $9) > $10 = 0 > >> >> >> On 21 May 2024 17:50:27 CEST, Tomas Volf <~@wolfsden.cz> wrote: >> >On 2024-05-21 17:33:24 +0200, Tristan Kohl via wrote: >> >> Hello Felix, >> >> >> >> my last message was not to critizise your help but rather my frustration with my own limited progress. I really appreciate the help! >> >> >> >> program-file at least results in a usable thing however since the script gets executed by smard I get the "command not found" in my logs. It seems like curl is not in PATH for smartd. Do I need to import something into the gexp? >> >> >> >> Also those env variables are defined by smartd during runtime depending on which drive produced the error. Therefore I need shell expansion/env variables and have to use system (without *) imho. >> >> >> >> This is the current state: >> >> >> >> (define-smartd-send-ntfy >> >> (program-file "send-ntfy" >> >> #~(system >> >> (string-append "curl " "-H \"Title: $SMARTD_SUBJECT\" " ...)))) >> > >> >Ignoring the obvious quoting issues here (what Felix does with `getenv' seems >> >much safer, and should produce the same result?), >> > >> >> >> >> Note: when using system* the error is: >> >> In execvp of curl: No such file or directory >> > >> >This should be solvable by using `file-append', so, basing on the system* >> >variant, something like: >> > >> > #~(system* #$(file-append curl "/bin/curl") <other-arguments-here>) >> > >> >Should invoke curl by absolute path. (You need import (gnu packages curl) of >> >course.) >> > >> >Hope this helps, >> >Tomas >> > >> >-- >> >There are only two hard things in Computer Science: >> >cache invalidation, naming things and off-by-one errors. > >Have a nice day, >Tomas > >-- >There are only two hard things in Computer Science: >cache invalidation, naming things and off-by-one errors. ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-05-31 13:43 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <4D873504-6540-477A-A2DB-DE293395CAFC.ref@ymail.com> 2024-05-19 22:48 ` How to configure smartd and send notifications? Tristan Kohl via 2024-05-20 11:30 ` Felix Lechner via 2024-05-20 13:56 ` Tristan Kohl via 2024-05-20 15:04 ` Felix Lechner via 2024-05-20 19:15 ` Tristan Kohl via 2024-05-20 23:42 ` Felix Lechner via 2024-05-21 15:33 ` Tristan Kohl via 2024-05-21 15:50 ` Tomas Volf 2024-05-23 19:25 ` Tristan Kohl via 2024-05-24 4:10 ` Felix Lechner via 2024-05-24 10:19 ` Tomas Volf 2024-05-31 13:42 ` Tristan Kohl via
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/guix.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.