You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@ambari.apache.org by yao lei <le...@163.com> on 2017/03/03 11:56:48 UTC

Review Request 57281: Script-Based Alert Dispathers support passing more parameters to script

-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57281/
-----------------------------------------------------------

Review request for Ambari and Jonathan Hurley.


Bugs: AMBARI-20291
    https://issues.apache.org/jira/browse/AMBARI-20291


Repository: ambari


Description
-------

Script-Based Alert Dispatcher now pass five parameters to script,including alert definition name, definition label,service name, alert state, and alert text.
But if script can receive other two parameters from dispather,it will be better.
1.hostname.
Because hostname the alert for is not always included in alert text,although it may be null like aggregate alerts.
With it we can more quick to find the related host that occured alert.
2.alert timestamp.
We may need to know the alert occurrence time ( state change time) more exactly. After the alert happened,it will spend some time to schedule the script to run.
Without it,we can only regard the script start time as the alert occurrence time.

We now use this feature to send alert information to mobile phone and suggest also passing hostname and alert timestamp.


Diffs
-----

  ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java 907588d 
  ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java 174f31f 
  ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java 9e0e406 


Diff: https://reviews.apache.org/r/57281/diff/1/


Testing
-------

1.cd ambari-server
   mvn test

2.write a python script to receive parameters from dispatcher

<code>
#!/usr/bin/python
import sys
import logging

def main():
    definitionName = sys.argv[1]
    definitionLabel = sys.argv[2]
    serviceName = sys.argv[3]
    alertState = sys.argv[4]
    alertText = sys.argv[5]
    alertTimestamp = sys.argv[6]
    hostname = sys.argv[7] if len(sys.argv)-1 == 7 else None

    logFile='/var/log/ambari-server/log_py.log'

    logging.basicConfig(filename = logFile, level = logging.DEBUG)
    logging.debug('received ' + str(len(sys.argv)-1) + ' parameters')
    for i in range(1, len(sys.argv)):
        logging.debug('parameter ' +str(i) + ':' +str(sys.argv[i]))

if __name__ == '__main__':
   main()
</code>

Stop and start any service like HDFS , we can see the expected result in /var/log/ambari-server/log_py.log,

3.write a shell script to  receive parameters from dispatcher

<code>
#!/bin/bash
logFile=/var/log/ambari-server/log_sh.log
definitionName=$1
definitionLabel=$2
serviceName=$3
alertState=$4 
alertText=$5
alertTimestamp=$6
hostname=$7

echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, $alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
</code>

Stop and start any service like HDFS , we can see the expected result in /var/ambari-server/log_sh.log, we can see the expected result.


Thanks,

yao lei


Re: Review Request 57281: Script-Based Alert Dispathers support passing more parameters to script

Posted by yao lei <le...@163.com>.

> On \u4e09\u6708 3, 2017, 6:48 p.m., Alejandro Fernandez wrote:
> > Ship It!

Thank for reviewing this patch


- yao


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57281/#review167857
-----------------------------------------------------------


On \u4e09\u6708 3, 2017, 11:56 a.m., yao lei wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/57281/
> -----------------------------------------------------------
> 
> (Updated \u4e09\u6708 3, 2017, 11:56 a.m.)
> 
> 
> Review request for Ambari and Jonathan Hurley.
> 
> 
> Bugs: AMBARI-20291
>     https://issues.apache.org/jira/browse/AMBARI-20291
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> Script-Based Alert Dispatcher now pass five parameters to script,including alert definition name, definition label,service name, alert state, and alert text.
> But if script can receive other two parameters from dispather,it will be better.
> 1.hostname.
> Because hostname the alert for is not always included in alert text,although it may be null like aggregate alerts.
> With it we can more quick to find the related host that occured alert.
> 2.alert timestamp.
> We may need to know the alert occurrence time ( state change time) more exactly. After the alert happened,it will spend some time to schedule the script to run.
> Without it,we can only regard the script start time as the alert occurrence time.
> 
> We now use this feature to send alert information to mobile phone and suggest also passing hostname and alert timestamp.
> 
> 
> Diffs
> -----
> 
>   ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java 907588d 
>   ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java 174f31f 
>   ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java 9e0e406 
> 
> 
> Diff: https://reviews.apache.org/r/57281/diff/1/
> 
> 
> Testing
> -------
> 
> 1.cd ambari-server
>    mvn test
> 
> 2.write a python script to receive parameters from dispatcher
> 
> <code>
> #!/usr/bin/python
> import sys
> import logging
> 
> def main():
>     definitionName = sys.argv[1]
>     definitionLabel = sys.argv[2]
>     serviceName = sys.argv[3]
>     alertState = sys.argv[4]
>     alertText = sys.argv[5]
>     alertTimestamp = sys.argv[6]
>     hostname = sys.argv[7] if len(sys.argv)-1 == 7 else None
> 
>     logFile='/var/log/ambari-server/log_py.log'
> 
>     logging.basicConfig(filename = logFile, level = logging.DEBUG)
>     logging.debug('received ' + str(len(sys.argv)-1) + ' parameters')
>     for i in range(1, len(sys.argv)):
>         logging.debug('parameter ' +str(i) + ':' +str(sys.argv[i]))
> 
> if __name__ == '__main__':
>    main()
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/log/ambari-server/log_py.log,
> 
> 3.write a shell script to  receive parameters from dispatcher
> 
> <code>
> #!/bin/bash
> logFile=/var/log/ambari-server/log_sh.log
> definitionName=$1
> definitionLabel=$2
> serviceName=$3
> alertState=$4 
> alertText=$5
> alertTimestamp=$6
> hostname=$7
> 
> echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, $alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/ambari-server/log_sh.log, we can see the expected result.
> 
> 
> Thanks,
> 
> yao lei
> 
>


Re: Review Request 57281: Script-Based Alert Dispathers support passing more parameters to script

Posted by Alejandro Fernandez <af...@hortonworks.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57281/#review167857
-----------------------------------------------------------


Ship it!




Ship It!

- Alejandro Fernandez


On March 3, 2017, 11:56 a.m., yao lei wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/57281/
> -----------------------------------------------------------
> 
> (Updated March 3, 2017, 11:56 a.m.)
> 
> 
> Review request for Ambari and Jonathan Hurley.
> 
> 
> Bugs: AMBARI-20291
>     https://issues.apache.org/jira/browse/AMBARI-20291
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> Script-Based Alert Dispatcher now pass five parameters to script,including alert definition name, definition label,service name, alert state, and alert text.
> But if script can receive other two parameters from dispather,it will be better.
> 1.hostname.
> Because hostname the alert for is not always included in alert text,although it may be null like aggregate alerts.
> With it we can more quick to find the related host that occured alert.
> 2.alert timestamp.
> We may need to know the alert occurrence time ( state change time) more exactly. After the alert happened,it will spend some time to schedule the script to run.
> Without it,we can only regard the script start time as the alert occurrence time.
> 
> We now use this feature to send alert information to mobile phone and suggest also passing hostname and alert timestamp.
> 
> 
> Diffs
> -----
> 
>   ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java 907588d 
>   ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java 174f31f 
>   ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java 9e0e406 
> 
> 
> Diff: https://reviews.apache.org/r/57281/diff/1/
> 
> 
> Testing
> -------
> 
> 1.cd ambari-server
>    mvn test
> 
> 2.write a python script to receive parameters from dispatcher
> 
> <code>
> #!/usr/bin/python
> import sys
> import logging
> 
> def main():
>     definitionName = sys.argv[1]
>     definitionLabel = sys.argv[2]
>     serviceName = sys.argv[3]
>     alertState = sys.argv[4]
>     alertText = sys.argv[5]
>     alertTimestamp = sys.argv[6]
>     hostname = sys.argv[7] if len(sys.argv)-1 == 7 else None
> 
>     logFile='/var/log/ambari-server/log_py.log'
> 
>     logging.basicConfig(filename = logFile, level = logging.DEBUG)
>     logging.debug('received ' + str(len(sys.argv)-1) + ' parameters')
>     for i in range(1, len(sys.argv)):
>         logging.debug('parameter ' +str(i) + ':' +str(sys.argv[i]))
> 
> if __name__ == '__main__':
>    main()
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/log/ambari-server/log_py.log,
> 
> 3.write a shell script to  receive parameters from dispatcher
> 
> <code>
> #!/bin/bash
> logFile=/var/log/ambari-server/log_sh.log
> definitionName=$1
> definitionLabel=$2
> serviceName=$3
> alertState=$4 
> alertText=$5
> alertTimestamp=$6
> hostname=$7
> 
> echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, $alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/ambari-server/log_sh.log, we can see the expected result.
> 
> 
> Thanks,
> 
> yao lei
> 
>


Re: Review Request 57281: Script-Based Alert Dispathers support passing more parameters to script

Posted by yao lei <le...@163.com>.

> On \u4e09\u6708 6, 2017, 2:21 p.m., Jonathan Hurley wrote:
> > Ship It!

Hi Jonathan,
Thank you very much.
Would you please help me to commit the patch to trunk if you are free?


- yao


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57281/#review167979
-----------------------------------------------------------


On \u4e09\u6708 3, 2017, 11:56 a.m., yao lei wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/57281/
> -----------------------------------------------------------
> 
> (Updated \u4e09\u6708 3, 2017, 11:56 a.m.)
> 
> 
> Review request for Ambari and Jonathan Hurley.
> 
> 
> Bugs: AMBARI-20291
>     https://issues.apache.org/jira/browse/AMBARI-20291
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> Script-Based Alert Dispatcher now pass five parameters to script,including alert definition name, definition label,service name, alert state, and alert text.
> But if script can receive other two parameters from dispather,it will be better.
> 1.hostname.
> Because hostname the alert for is not always included in alert text,although it may be null like aggregate alerts.
> With it we can more quick to find the related host that occured alert.
> 2.alert timestamp.
> We may need to know the alert occurrence time ( state change time) more exactly. After the alert happened,it will spend some time to schedule the script to run.
> Without it,we can only regard the script start time as the alert occurrence time.
> 
> We now use this feature to send alert information to mobile phone and suggest also passing hostname and alert timestamp.
> 
> 
> Diffs
> -----
> 
>   ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java 907588d 
>   ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java 174f31f 
>   ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java 9e0e406 
> 
> 
> Diff: https://reviews.apache.org/r/57281/diff/1/
> 
> 
> Testing
> -------
> 
> 1.cd ambari-server
>    mvn test
> 
> 2.write a python script to receive parameters from dispatcher
> 
> <code>
> #!/usr/bin/python
> import sys
> import logging
> 
> def main():
>     definitionName = sys.argv[1]
>     definitionLabel = sys.argv[2]
>     serviceName = sys.argv[3]
>     alertState = sys.argv[4]
>     alertText = sys.argv[5]
>     alertTimestamp = sys.argv[6]
>     hostname = sys.argv[7] if len(sys.argv)-1 == 7 else None
> 
>     logFile='/var/log/ambari-server/log_py.log'
> 
>     logging.basicConfig(filename = logFile, level = logging.DEBUG)
>     logging.debug('received ' + str(len(sys.argv)-1) + ' parameters')
>     for i in range(1, len(sys.argv)):
>         logging.debug('parameter ' +str(i) + ':' +str(sys.argv[i]))
> 
> if __name__ == '__main__':
>    main()
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/log/ambari-server/log_py.log,
> 
> 3.write a shell script to  receive parameters from dispatcher
> 
> <code>
> #!/bin/bash
> logFile=/var/log/ambari-server/log_sh.log
> definitionName=$1
> definitionLabel=$2
> serviceName=$3
> alertState=$4 
> alertText=$5
> alertTimestamp=$6
> hostname=$7
> 
> echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, $alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/ambari-server/log_sh.log, we can see the expected result.
> 
> 
> Thanks,
> 
> yao lei
> 
>


Re: Review Request 57281: Script-Based Alert Dispathers support passing more parameters to script

Posted by Jonathan Hurley <jh...@hortonworks.com>.

> On March 6, 2017, 9:21 a.m., Jonathan Hurley wrote:
> > Ship It!
> 
> yao lei wrote:
>     Hi Jonathan,
>     Thank you very much.
>     Would you please help me to commit the patch to trunk if you are free?
> 
> Jonathan Hurley wrote:
>     Yes, I'm just running a quick test on this patch locally and I'll commit it shortly once it passes...

Committed. Please close the review.


- Jonathan


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57281/#review167979
-----------------------------------------------------------


On March 3, 2017, 6:56 a.m., yao lei wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/57281/
> -----------------------------------------------------------
> 
> (Updated March 3, 2017, 6:56 a.m.)
> 
> 
> Review request for Ambari and Jonathan Hurley.
> 
> 
> Bugs: AMBARI-20291
>     https://issues.apache.org/jira/browse/AMBARI-20291
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> Script-Based Alert Dispatcher now pass five parameters to script,including alert definition name, definition label,service name, alert state, and alert text.
> But if script can receive other two parameters from dispather,it will be better.
> 1.hostname.
> Because hostname the alert for is not always included in alert text,although it may be null like aggregate alerts.
> With it we can more quick to find the related host that occured alert.
> 2.alert timestamp.
> We may need to know the alert occurrence time ( state change time) more exactly. After the alert happened,it will spend some time to schedule the script to run.
> Without it,we can only regard the script start time as the alert occurrence time.
> 
> We now use this feature to send alert information to mobile phone and suggest also passing hostname and alert timestamp.
> 
> 
> Diffs
> -----
> 
>   ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java 907588d 
>   ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java 174f31f 
>   ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java 9e0e406 
> 
> 
> Diff: https://reviews.apache.org/r/57281/diff/1/
> 
> 
> Testing
> -------
> 
> 1.cd ambari-server
>    mvn test
> 
> 2.write a python script to receive parameters from dispatcher
> 
> <code>
> #!/usr/bin/python
> import sys
> import logging
> 
> def main():
>     definitionName = sys.argv[1]
>     definitionLabel = sys.argv[2]
>     serviceName = sys.argv[3]
>     alertState = sys.argv[4]
>     alertText = sys.argv[5]
>     alertTimestamp = sys.argv[6]
>     hostname = sys.argv[7] if len(sys.argv)-1 == 7 else None
> 
>     logFile='/var/log/ambari-server/log_py.log'
> 
>     logging.basicConfig(filename = logFile, level = logging.DEBUG)
>     logging.debug('received ' + str(len(sys.argv)-1) + ' parameters')
>     for i in range(1, len(sys.argv)):
>         logging.debug('parameter ' +str(i) + ':' +str(sys.argv[i]))
> 
> if __name__ == '__main__':
>    main()
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/log/ambari-server/log_py.log,
> 
> 3.write a shell script to  receive parameters from dispatcher
> 
> <code>
> #!/bin/bash
> logFile=/var/log/ambari-server/log_sh.log
> definitionName=$1
> definitionLabel=$2
> serviceName=$3
> alertState=$4 
> alertText=$5
> alertTimestamp=$6
> hostname=$7
> 
> echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, $alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/ambari-server/log_sh.log, we can see the expected result.
> 
> 
> Thanks,
> 
> yao lei
> 
>


Re: Review Request 57281: Script-Based Alert Dispathers support passing more parameters to script

Posted by yao lei <le...@163.com>.

> On \u4e09\u6708 6, 2017, 2:21 p.m., Jonathan Hurley wrote:
> > Ship It!
> 
> yao lei wrote:
>     Hi Jonathan,
>     Thank you very much.
>     Would you please help me to commit the patch to trunk if you are free?
> 
> Jonathan Hurley wrote:
>     Yes, I'm just running a quick test on this patch locally and I'll commit it shortly once it passes...
> 
> Jonathan Hurley wrote:
>     Committed. Please close the review.

Thank you again.I will close it later


- yao


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57281/#review167979
-----------------------------------------------------------


On \u4e09\u6708 3, 2017, 11:56 a.m., yao lei wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/57281/
> -----------------------------------------------------------
> 
> (Updated \u4e09\u6708 3, 2017, 11:56 a.m.)
> 
> 
> Review request for Ambari and Jonathan Hurley.
> 
> 
> Bugs: AMBARI-20291
>     https://issues.apache.org/jira/browse/AMBARI-20291
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> Script-Based Alert Dispatcher now pass five parameters to script,including alert definition name, definition label,service name, alert state, and alert text.
> But if script can receive other two parameters from dispather,it will be better.
> 1.hostname.
> Because hostname the alert for is not always included in alert text,although it may be null like aggregate alerts.
> With it we can more quick to find the related host that occured alert.
> 2.alert timestamp.
> We may need to know the alert occurrence time ( state change time) more exactly. After the alert happened,it will spend some time to schedule the script to run.
> Without it,we can only regard the script start time as the alert occurrence time.
> 
> We now use this feature to send alert information to mobile phone and suggest also passing hostname and alert timestamp.
> 
> 
> Diffs
> -----
> 
>   ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java 907588d 
>   ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java 174f31f 
>   ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java 9e0e406 
> 
> 
> Diff: https://reviews.apache.org/r/57281/diff/1/
> 
> 
> Testing
> -------
> 
> 1.cd ambari-server
>    mvn test
> 
> 2.write a python script to receive parameters from dispatcher
> 
> <code>
> #!/usr/bin/python
> import sys
> import logging
> 
> def main():
>     definitionName = sys.argv[1]
>     definitionLabel = sys.argv[2]
>     serviceName = sys.argv[3]
>     alertState = sys.argv[4]
>     alertText = sys.argv[5]
>     alertTimestamp = sys.argv[6]
>     hostname = sys.argv[7] if len(sys.argv)-1 == 7 else None
> 
>     logFile='/var/log/ambari-server/log_py.log'
> 
>     logging.basicConfig(filename = logFile, level = logging.DEBUG)
>     logging.debug('received ' + str(len(sys.argv)-1) + ' parameters')
>     for i in range(1, len(sys.argv)):
>         logging.debug('parameter ' +str(i) + ':' +str(sys.argv[i]))
> 
> if __name__ == '__main__':
>    main()
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/log/ambari-server/log_py.log,
> 
> 3.write a shell script to  receive parameters from dispatcher
> 
> <code>
> #!/bin/bash
> logFile=/var/log/ambari-server/log_sh.log
> definitionName=$1
> definitionLabel=$2
> serviceName=$3
> alertState=$4 
> alertText=$5
> alertTimestamp=$6
> hostname=$7
> 
> echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, $alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/ambari-server/log_sh.log, we can see the expected result.
> 
> 
> Thanks,
> 
> yao lei
> 
>


Re: Review Request 57281: Script-Based Alert Dispathers support passing more parameters to script

Posted by Jonathan Hurley <jh...@hortonworks.com>.

> On March 6, 2017, 9:21 a.m., Jonathan Hurley wrote:
> > Ship It!
> 
> yao lei wrote:
>     Hi Jonathan,
>     Thank you very much.
>     Would you please help me to commit the patch to trunk if you are free?

Yes, I'm just running a quick test on this patch locally and I'll commit it shortly once it passes...


- Jonathan


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57281/#review167979
-----------------------------------------------------------


On March 3, 2017, 6:56 a.m., yao lei wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/57281/
> -----------------------------------------------------------
> 
> (Updated March 3, 2017, 6:56 a.m.)
> 
> 
> Review request for Ambari and Jonathan Hurley.
> 
> 
> Bugs: AMBARI-20291
>     https://issues.apache.org/jira/browse/AMBARI-20291
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> Script-Based Alert Dispatcher now pass five parameters to script,including alert definition name, definition label,service name, alert state, and alert text.
> But if script can receive other two parameters from dispather,it will be better.
> 1.hostname.
> Because hostname the alert for is not always included in alert text,although it may be null like aggregate alerts.
> With it we can more quick to find the related host that occured alert.
> 2.alert timestamp.
> We may need to know the alert occurrence time ( state change time) more exactly. After the alert happened,it will spend some time to schedule the script to run.
> Without it,we can only regard the script start time as the alert occurrence time.
> 
> We now use this feature to send alert information to mobile phone and suggest also passing hostname and alert timestamp.
> 
> 
> Diffs
> -----
> 
>   ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java 907588d 
>   ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java 174f31f 
>   ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java 9e0e406 
> 
> 
> Diff: https://reviews.apache.org/r/57281/diff/1/
> 
> 
> Testing
> -------
> 
> 1.cd ambari-server
>    mvn test
> 
> 2.write a python script to receive parameters from dispatcher
> 
> <code>
> #!/usr/bin/python
> import sys
> import logging
> 
> def main():
>     definitionName = sys.argv[1]
>     definitionLabel = sys.argv[2]
>     serviceName = sys.argv[3]
>     alertState = sys.argv[4]
>     alertText = sys.argv[5]
>     alertTimestamp = sys.argv[6]
>     hostname = sys.argv[7] if len(sys.argv)-1 == 7 else None
> 
>     logFile='/var/log/ambari-server/log_py.log'
> 
>     logging.basicConfig(filename = logFile, level = logging.DEBUG)
>     logging.debug('received ' + str(len(sys.argv)-1) + ' parameters')
>     for i in range(1, len(sys.argv)):
>         logging.debug('parameter ' +str(i) + ':' +str(sys.argv[i]))
> 
> if __name__ == '__main__':
>    main()
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/log/ambari-server/log_py.log,
> 
> 3.write a shell script to  receive parameters from dispatcher
> 
> <code>
> #!/bin/bash
> logFile=/var/log/ambari-server/log_sh.log
> definitionName=$1
> definitionLabel=$2
> serviceName=$3
> alertState=$4 
> alertText=$5
> alertTimestamp=$6
> hostname=$7
> 
> echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, $alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/ambari-server/log_sh.log, we can see the expected result.
> 
> 
> Thanks,
> 
> yao lei
> 
>


Re: Review Request 57281: Script-Based Alert Dispathers support passing more parameters to script

Posted by Jonathan Hurley <jh...@hortonworks.com>.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/57281/#review167979
-----------------------------------------------------------


Ship it!




Ship It!

- Jonathan Hurley


On March 3, 2017, 6:56 a.m., yao lei wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/57281/
> -----------------------------------------------------------
> 
> (Updated March 3, 2017, 6:56 a.m.)
> 
> 
> Review request for Ambari and Jonathan Hurley.
> 
> 
> Bugs: AMBARI-20291
>     https://issues.apache.org/jira/browse/AMBARI-20291
> 
> 
> Repository: ambari
> 
> 
> Description
> -------
> 
> Script-Based Alert Dispatcher now pass five parameters to script,including alert definition name, definition label,service name, alert state, and alert text.
> But if script can receive other two parameters from dispather,it will be better.
> 1.hostname.
> Because hostname the alert for is not always included in alert text,although it may be null like aggregate alerts.
> With it we can more quick to find the related host that occured alert.
> 2.alert timestamp.
> We may need to know the alert occurrence time ( state change time) more exactly. After the alert happened,it will spend some time to schedule the script to run.
> Without it,we can only regard the script start time as the alert occurrence time.
> 
> We now use this feature to send alert information to mobile phone and suggest also passing hostname and alert timestamp.
> 
> 
> Diffs
> -----
> 
>   ambari-server/src/main/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcher.java 907588d 
>   ambari-server/src/main/java/org/apache/ambari/server/state/services/AlertNoticeDispatchService.java 174f31f 
>   ambari-server/src/test/java/org/apache/ambari/server/notifications/dispatchers/AlertScriptDispatcherTest.java 9e0e406 
> 
> 
> Diff: https://reviews.apache.org/r/57281/diff/1/
> 
> 
> Testing
> -------
> 
> 1.cd ambari-server
>    mvn test
> 
> 2.write a python script to receive parameters from dispatcher
> 
> <code>
> #!/usr/bin/python
> import sys
> import logging
> 
> def main():
>     definitionName = sys.argv[1]
>     definitionLabel = sys.argv[2]
>     serviceName = sys.argv[3]
>     alertState = sys.argv[4]
>     alertText = sys.argv[5]
>     alertTimestamp = sys.argv[6]
>     hostname = sys.argv[7] if len(sys.argv)-1 == 7 else None
> 
>     logFile='/var/log/ambari-server/log_py.log'
> 
>     logging.basicConfig(filename = logFile, level = logging.DEBUG)
>     logging.debug('received ' + str(len(sys.argv)-1) + ' parameters')
>     for i in range(1, len(sys.argv)):
>         logging.debug('parameter ' +str(i) + ':' +str(sys.argv[i]))
> 
> if __name__ == '__main__':
>    main()
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/log/ambari-server/log_py.log,
> 
> 3.write a shell script to  receive parameters from dispatcher
> 
> <code>
> #!/bin/bash
> logFile=/var/log/ambari-server/log_sh.log
> definitionName=$1
> definitionLabel=$2
> serviceName=$3
> alertState=$4 
> alertText=$5
> alertTimestamp=$6
> hostname=$7
> 
> echo received $# parameters:  $definitionName, $definitionLabel, $serviceName, $alertState ,$alertText ,$alertTimestamp, $hostname  >> $logFile
> </code>
> 
> Stop and start any service like HDFS , we can see the expected result in /var/ambari-server/log_sh.log, we can see the expected result.
> 
> 
> Thanks,
> 
> yao lei
> 
>