Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: [RESOLVED]SMS by 123-SMS

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    10

    [RESOLVED]SMS by 123-SMS

    Hello everybody,

    I want use 123-SMS to sent notification. I want use HTTP request, so i write a "bash" script. When i run my script from shell (with user shinken) it's ok, i receive a sms.
    To use for notification i define this command :
    Code:
    ## Notify Service by SMS (123-SMS)
    # You need both reactionner_tag and module_type in most cases!
    define command {
      command_name    notify-service-by-123-sms-http
      command_line    /opt/envoi_sms_123sms.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTNAME$ $SERVICESTATE$
    }
    
    ## Notify host by SMS (123-SMS)
    # You need both reactionner_tag and module_type in most cases!
    define command {
      command_name    notify-host-by-123-sms-http
      command_line    /opt/envoi_sms_123sms.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTNAME$ $SERVICESTATE$
    }
    I define a contact with this command
    Code:
     
    define contact{
      contact_name          alain
      alias              Alain
      host_notifications_enabled   1
      service_notifications_enabled  1
      service_notification_period   24x7
      host_notification_period    24x7
      service_notification_options  w,u,c,r
      host_notification_options    d,u,r
    #  service_notification_commands  notify-service-by-123-sms
    #  host_notification_commands   notify-host-by-123-sms
      service_notification_commands  notify-service-by-123-sms-http
      host_notification_commands   notify-host-by-123-sms-http
      service_notification_commands  notify-service-by-email
      host_notification_commands   notify-host-by-email
    
      email              toto.titi@me.net
      pager              0123456789
      can_submit_commands       1
      is_admin
    }            1
    My script /opt/envoi_sms_123sms.sh
    Code:
    #!/bin/bash
    
    # en parametre : numero_de_tel, type, host , service, etat
    
    date > ~/datesms
    
    NOTIFICATIONTYPE=$2
    HOSTALIAS=$3
    SERVICEDESC=$4
    SERVICESTATE=$5
    textesms="**"$NOTIFICATIONTYPE" alerte - "$HOSTALIAS"/"$SERVICEDESC" is "$SERVICESTATE" **"
    wget -o ~/logenvoisms -O ~/reponse "http://www.123-SMS.net/http.php?email=toto.titi@me.net&pass=********&numero=$1&message=$textesms
    
    exit 0
    I receive email but no sms. I don't find file "datesms" in /home/shinken ou /root.

    It's possible to run sh script for notification ?

    Best regard's

  2. #2
    Shinken project leader
    Join Date
    May 2011
    Location
    Bordeaux (France)
    Posts
    2,131

    Re: SMS by 123-SMS

    Look at your scheduler.log, if the notification command fail, it will be put there with a warning log level.
    No direct support by personal message. Please open a thread so everyone can see the solution

  3. #3
    Administrator
    Join Date
    Jun 2011
    Posts
    216

    Re: SMS by 123-SMS

    Aren't you overriding your own field with this conf?

    Quote Originally Posted by "Official Doc"
    host_notification_commands

    This directive is used to define a list of the short names of the commands used to notify the contact of a host problem or recovery. Multiple notification commands should be separated by commas. All notification commands are executed when the contact needs to be notified. The maximum amount of time that a notification command can run is controlled by the notification_timeout option.

    [...]


    service_notification_commands

    This directive is used to define a list of the short names of the commands used to notify the contact of a service problem or recovery. Multiple notification commands should be separated by commas. All notification commands are executed when the contact needs to be notified. The maximum amount of time that a notification command can run is controlled by the notification_timeout option.
    Can you try
    Code:
      service_notification_commands  notify-service-by-123-sms-http, notify-service-by-email
      host_notification_commands   notify-host-by-123-sms-http, notify-host-by-email
    Instead of your actual conf?

  4. #4
    Junior Member
    Join Date
    Dec 2012
    Posts
    10

    Re: SMS by 123-SMS

    Hello,

    thank's to napuraba and thank's to Seb-Solon.

    In scheduler.log i have

    2012-12-17 16:28:09,595 [1355761689] SERVICE ALERT: lxctext;Ssh;OK;HARD;2;SSH OK - OpenSSH_5.3p1 Debian-3ubuntu3 (protocol 2.0)
    2012-12-17 16:28:10,393 [1355761690] SERVICE NOTIFICATION: admin;lxctext;Ssh;OK;notify-service-by-123-sms-http;SSH OK - OpenSSH_5.3p1 Debian-3ubuntu3 (protocol 2.0)
    2012-12-17 16:28:10,394 [1355761690] SERVICE NOTIFICATION: alain;lxctext;Ssh;OK;notify-service-by-email;SSH OK - OpenSSH_5.3p1 Debian-3ubuntu3 (protocol 2.0)

    but no file "datesms" created.

    I'll try Seb-Solon code ......

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    10

    Re: SMS by 123-SMS

    I tried Seb-Solon's code : script sh not send.

    In scheduler.log i have :
    Code:
    2012-12-17 16:49:00,401 [1355762940] Info :  Waiting for initial configuration
    2012-12-17 16:49:00,401 [1355762940] Info :  New configuration received
    2012-12-17 16:49:00,410 [1355762940] Info :  Trying to init module: PickleRetention
    2012-12-17 16:49:00,410 [1355762940] Info :  I correctly loaded the modules: [PickleRetention]
    2012-12-17 16:49:00,410 [1355762940] Info :  Loading configuration.
    2012-12-17 16:49:00,414 [1355762940] Info :  New configuration loaded
    2012-12-17 16:49:00,416 [1355762940] Info :  [PickleRetentionGeneric] Retention objects loaded successfully.
    2012-12-17 16:49:00,425 [1355762940] Info :  [scheduler-1] Created initial Broks: 282
    2012-12-17 16:49:00,425 [1355762940] Info :  [scheduler-1] First scheduling launched
    2012-12-17 16:49:00,427 [1355762940] Info :  [scheduler-1] First scheduling done
    2012-12-17 16:53:17,653 [1355763197] SERVICE ALERT: lxctext;Ssh;CRITICAL;SOFT;1;CRITICAL - Socket timeout after 10 seconds
    2012-12-17 16:54:13,702 [1355763253] SERVICE ALERT: lxctext;Ssh;CRITICAL;HARD;2;No route to host
    2012-12-17 16:54:14,222 [1355763254] SERVICE NOTIFICATION: admin;lxctext;Ssh;CRITICAL;notify-service-by-123-sms;No route to host
    2012-12-17 16:54:14,223 [1355763254] SERVICE NOTIFICATION: alain;lxctext;Ssh;CRITICAL;notify-service-by-123-sms-http;No route to host
    2012-12-17 16:54:14,223 [1355763254] SERVICE NOTIFICATION: alain;lxctext;Ssh;CRITICAL;notify-service-by-email;No route to host
    2012-12-17 16:54:14,223 [1355763254] SERVICE NOTIFICATION: alain;lxctext;Ssh;CRITICAL;notify-service-by-123-sms;No route to host
    in templates.cfg :
    Code:
    # Contact definition
    # By default the contact will ask notification by mails
    define contact{
        name              generic-contact     ; The name of this contact template
        register            0            ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        host_notifications_enabled   1
        service_notifications_enabled  1
        email              shinken@localhost
        can_submit_commands       1
        notificationways        email
        notificationways        123sms
        notifycationways        123smshttp
        }
    
    # This is how emails are sent, 24x7 way.
    define notificationway{
        notificationway_name      email
        service_notification_period   24x7
        host_notification_period    24x7
        service_notification_options  c,w,r
        host_notification_options    d,u,r,f,s
        service_notification_commands  notify-service-by-email ; send service notifications via email
        host_notification_commands   notify-host-by-email  ; send host notifications via email
    }
    
    define notificationway{
        notificationway_name      123sms
        service_notification_period   24x7
        host_notification_period    24x7
        service_notification_options  c,w,r
        host_notification_options    d,u,r,f,s
        service_notification_commands  notify-service-by-123-sms ; send service notifications via email
        host_notification_commands   notify-host-by-123-sms  ; send host notifications via email
    }
    
    define notificationway{
        notificationway_name      123smshttp
        service_notification_period   24x7
        host_notification_period    24x7
        service_notification_options  c,w,r
        host_notification_options    d,u,r,f,s
        service_notification_commands  notify-service-by-123-sms-http ; send service notifications via email
        host_notification_commands   notify-host-by-123-sms-http  ; send host notifications via email
    }
    In contacts.cfg :
    Code:
    define contact{
      use       generic-contact
      contact_name  admin
      email      toto.titi@me.net
      pager      0123456789  ; contact phone number
      password    admin
      is_admin    1
    #  +service_notification_commands  notify-service-by-123-sms-http
    #  +host_notification_commands   notify-host-by-123-sms-http
    
    }
    
    
    # This is a default guest user
    # CHANGE ITS PASSWORD or remove it
    define contact{
      use         generic-contact
      contact_name    guest
      email        none
      password      guest
      can_submit_commands 0
    }
    
    define contact{
      contact_name          alain
      alias                 Alain
      host_notifications_enabled   1
      service_notifications_enabled  1
      service_notification_period   24x7
      host_notification_period    24x7
      service_notification_options  w,u,c,r
      host_notification_options    d,u,r
      service_notification_commands  notify-service-by-123-sms-http,notify-service-by-123-sms,notify-service-by-email
      host_notification_commands   notify-host-by-123-sms-http,notify-host-by-123-sms,notify-host-by-email
      email              toto.titi@me.net
      pager              0123456789
      can_submit_commands       1
      is_admin            1
    }
    In commands.cfg :
    Code:
    ## Notify Host by Email
    define command {
      command_name  notify-host-by-email
      command_line  /usr/bin/printf "%b" "Shinken Notification\n\nType:$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDate/Time: $DATE$\n" | /usr/b$
    }
    
    ## Notify Service by Email
    define command {
      command_name  notify-service-by-email
      command_line  /usr/bin/printf "%b" "Shinken Notification\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDat$
    }
    
    ## Notify Service by SMS (123-SMS)
    # You need both reactionner_tag and module_type in most cases!
    # 123-SMS par HTTP
    define command {
      command_name    notify-service-by-123-sms-http
      command_line    /opt/envoi_sms_123sms.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTNAME$ $SERVICESTATE$
    }
    
    ## Notify host by SMS (123-SMS)
    # You need both reactionner_tag and module_type in most cases!
    define command {
      command_name    notify-host-by-123-sms-http
      command_line    /opt/envoi_sms_123sms.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTNAME$ $SERVICESTATE$
    }
    
    # 123-SMS par email
    define command{
      command_name notify-service-by-123-sms
      command_line /usr/bin/printf “%s” **Date:\ $DATETIME$\ $NOTIFICATIONTYPE$\ alert\ -\ $HOSTNAME$/$SERVICEDESC$\ is\ $SERVICESTATE$\ ** | /usr/bin/mail -s passxxxx:$CONTACTPAGER$ sms@123-SMS.net
    }
    
    define command{
      command_name notify-host-by-123-sms
      command_line /usr/bin/printf “%s” “Host $HOSTSTATE$ alert for $HOSTNAME$!” | /usr/bin/mail -s passxxxx:$CONTACTPAGER$ sms@123-SMS.net
    }

  6. #6
    Administrator
    Join Date
    Jun 2011
    Posts
    216

    Re: SMS by 123-SMS

    Code:
    2012-12-17 16:54:14,222 [1355763254] SERVICE NOTIFICATION: admin;lxctext;Ssh;CRITICAL;notify-service-by-123-sms;No route to host
    2012-12-17 16:54:14,223 [1355763254] SERVICE NOTIFICATION: alain;lxctext;Ssh;CRITICAL;notify-service-by-123-sms-http;No route to host
    Means the notif was well defined. Is there something in date > ~/datesms?

    Can you try to add to your script a echo $* > ~/macro.tmp to see if all macros are corrects?

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    10

    Re: SMS by 123-SMS

    Hello,

    thank's for your answer.

    The file "datesms" is not create.

    I put " echo $* > ~/macro.tmp" in the script, but no file "macro.tmp" in /homeShinken (and no file in /root)

    I try "$PLUGINSDIR$/envoi_sms_123sms.sh" in commands.cfg and put script in libexec : no success.

    I try "mv libexec/envoi_sms_123sms.sh libexec/envoi123sms.sh" : no success

    If i modify scritp, i receive the email, so i think for a notification it's not possible run script sh in command_line.
    Code:
    # 123-SMS par HTTP
    define command {
      command_name    notify-service-by-123-sms-http
      # command_line    $PLUGINSDIR$/envoi123sms.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTNAME$ $SERVICESTATE$
      command_line    /usr/bin/mail -s "Host $HOSTSTATE$ alert for $HOSTNAME$!" $CONTACTEMAIL$
    }
    
    ## Notify host by SMS (123-SMS)
    # You need both reactionner_tag and module_type in most cases!
    define command {
      command_name    notify-host-by-123-sms-http
      # command_line    $PLUGINSDIR$/envoi123sms.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTNAME$ $SERVICESTATE$
      command_line    /usr/bin/mail -s "Host $HOSTSTATE$ alert for $HOSTNAME$!" $CONTACTEMAIL$
    }
    Best regard's

  8. #8
    Administrator
    Join Date
    Jun 2011
    Posts
    216

    Re: SMS by 123-SMS

    I'll try to reproduce this. But I use sh script in my env to fake mails (lazy to configure a mail server) and it works the way I want.

    It's like your script is not run, because the file is not created.

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    10

    Re: SMS by 123-SMS

    I "touch" the files
    Code:
    root@lxcshinken01:/usr/local/shinken# ls -al /home/shinken/
    total 24
    drwxr-xr-x 2 shinken shinken 4096 2012-12-19 10:01 .
    drwxr-xr-x 3 root  root  4096 2012-12-08 18:58 ..
    -rw------- 1 shinken shinken 609 2012-12-15 16:12 .bash_history
    -rw-r--r-- 1 shinken shinken 220 2010-04-19 02:15 .bash_logout
    -rw-r--r-- 1 shinken shinken 3103 2010-04-19 02:15 .bashrc
    -rwxrwxrwx 1 shinken shinken  0 2012-12-19 10:01 datesms
    -rwxrwxrwx 1 shinken shinken  0 2012-12-19 10:01 macro.tmp
    -rw-r--r-- 1 shinken shinken 675 2010-04-19 02:15 .profile
    then i try "/usr/bin/bash" in command_line
    Code:
    command_line    /usr/bin/bash $PLUGINSDIR$/envoi123sms.sh $CONTACTPAGER$ $NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTNAME$ $SERVICESTATE$
    but no effect ! :'(

    My new script :
    Code:
    #!/bin/bash
    # en parametre : numero_de_tel, type, host , service, etat
    
    echo $* > ~/macro.tmp
    date > ~/datesms
    
    exit 0

  10. #10
    Junior Member
    Join Date
    Dec 2012
    Posts
    10

    Re: SMS by 123-SMS

    My host :
    Distributor ID: Ubuntu
    Description: Ubuntu 10.04 LTS
    Release: 10.04
    Codename: lucid

    2.6.32-5-amd64

    In lxc container. Host lxc is a Debian.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •